def test_default_stake(self): i = InterventionFactory.create() i.stake = None self.assertTrue(i.stake is None) i.save() self.assertTrue(i.stake is None) lowstake = StakeFactory.create() highstake = StakeFactory.create() if lowstake > highstake: tmp = lowstake lowstake = highstake highstake = tmp # Add paths to topology infra = InfrastructureFactory.create(no_path=True) infra.add_path(PathFactory.create(stake=lowstake)) infra.add_path(PathFactory.create(stake=highstake)) infra.add_path(PathFactory.create(stake=lowstake)) i.set_topology(infra) # Stake is not None anymore i.save() self.assertFalse(i.stake is None) # Make sure it took higher stake self.assertEqual(i.stake, highstake)
def test_default_stake(self): i = InterventionFactory.create() i.stake = None self.assertTrue(i.stake is None) i.save() self.assertTrue(i.stake is None) lowstake = StakeFactory.create() highstake = StakeFactory.create() if lowstake > highstake: tmp = lowstake lowstake = highstake highstake = tmp # Add paths to topology infra = InfrastructureFactory.create(no_path=True) infra.add_path(PathFactory.create(stake=lowstake)) infra.add_path(PathFactory.create(stake=highstake)) infra.add_path(PathFactory.create(stake=lowstake)) i.set_infrastructure(infra) # Stake is not None anymore i.save() self.assertFalse(i.stake is None) # Make sure it took higher stake self.assertEqual(i.stake, highstake)
def test_comparison(self): low = StakeFactory.create() high = StakeFactory.create() # In case SERIAL field was reinitialized if high.pk < low.pk: tmp = high high = low low = tmp self.assertTrue(low.pk < high.pk) self.assertTrue(low < high) self.assertTrue(low <= high) self.assertFalse(low > high) self.assertFalse(low >= high) self.assertFalse(low == high)
def get_good_data(self): InterventionStatusFactory.create() # in case not any in db path = PathFactory.create() return { 'name': 'test', 'date': '2012-08-23', 'structure': default_structure().pk, 'disorders': InterventionDisorderFactory.create().pk, 'comments': '', 'slope': 0, 'area': 0, 'subcontract_cost': 0.0, 'stake': StakeFactory.create().pk, 'height': 0.0, 'project': '', 'width': 0.0, 'length': 0.0, 'status': InterventionStatus.objects.all()[0].pk, 'heliport_cost': 0.0, 'material_cost': 0.0, 'topology': '{"paths": [%s]}' % path.pk, 'manday_set-TOTAL_FORMS': '2', 'manday_set-INITIAL_FORMS': '0', 'manday_set-MAX_NUM_FORMS': '', 'manday_set-0-nb_days': '48.75', 'manday_set-0-job': InterventionJobFactory.create().pk, 'manday_set-0-id': '', 'manday_set-0-DELETE': '', 'manday_set-1-nb_days': '12', 'manday_set-1-job': InterventionJobFactory.create().pk, 'manday_set-1-id': '', 'manday_set-1-DELETE': '', }
def get_good_data(self): InterventionStatusFactory.create() # in case not any in db path = PathFactory.create() return { 'name': 'test', 'date': '2012-08-23', 'disorders': InterventionDisorderFactory.create().pk, 'comments': '', 'slope': 0, 'area': 0, 'subcontract_cost': 0.0, 'stake': StakeFactory.create().pk, 'height': 0.0, 'project': '', 'width': 0.0, 'length': 0.0, 'status': InterventionStatus.objects.all()[0].pk, 'heliport_cost': 0.0, 'material_cost': 0.0, 'topology': '{"paths": [%s]}' % path.pk, 'manday_set-TOTAL_FORMS': '2', 'manday_set-INITIAL_FORMS': '0', 'manday_set-MAX_NUM_FORMS': '', 'manday_set-0-nb_days': '48.75', 'manday_set-0-job': InterventionJobFactory.create().pk, 'manday_set-0-id': '', 'manday_set-0-DELETE': '', 'manday_set-1-nb_days': '12', 'manday_set-1-job': InterventionJobFactory.create().pk, 'manday_set-1-id': '', 'manday_set-1-DELETE': '', }
def get_good_data(self): InterventionStatusFactory.create() # in case not any in db path = PathFactory.create() return { "name": "test", "date": "2012-08-23", "structure": default_structure().pk, "disorders": InterventionDisorderFactory.create().pk, "comments": "", "slope": 0, "area": 0, "subcontract_cost": 0.0, "stake": StakeFactory.create().pk, "height": 0.0, "project": "", "width": 0.0, "length": 0.0, "status": InterventionStatus.objects.all()[0].pk, "heliport_cost": 0.0, "material_cost": 0.0, "topology": '{"paths": [%s]}' % path.pk, "manday_set-TOTAL_FORMS": "2", "manday_set-INITIAL_FORMS": "0", "manday_set-MAX_NUM_FORMS": "", "manday_set-0-nb_days": "48.75", "manday_set-0-job": InterventionJobFactory.create().pk, "manday_set-0-id": "", "manday_set-0-DELETE": "", "manday_set-1-nb_days": "12", "manday_set-1-job": InterventionJobFactory.create().pk, "manday_set-1-id": "", "manday_set-1-DELETE": "", }
def test_structurerelated_filter_with_none(self): s1 = StructureFactory.create() s2 = StructureFactory.create() st0 = StakeFactory.create(structure=None) st1 = StakeFactory.create(structure=s1) st2 = StakeFactory.create(structure=s2) user = self.userfactory(password='******') p = user.profile p.structure = s1 p.save() success = self.client.login(username=user.username, password='******') self.assertTrue(success) response = self.client.get(Path.get_add_url()) self.assertEqual(response.status_code, 200) self.assertTrue('form' in response.context) form = response.context['form'] self.assertTrue('stake' in form.fields) stakefield = form.fields['stake'] self.assertTrue((st0.pk, unicode(st0)) in stakefield.choices) self.assertTrue((st1.pk, unicode(st1)) in stakefield.choices) self.assertFalse((st2.pk, unicode(st2)) in stakefield.choices)
def test_structurerelated_filter(self): def test_structure(structure, stake): user = self.userfactory(password='******') p = user.profile p.structure = structure p.save() success = self.client.login(username=user.username, password='******') self.assertTrue(success) response = self.client.get(Path.get_add_url()) self.assertEqual(response.status_code, 200) self.assertTrue('form' in response.context) form = response.context['form'] self.assertTrue('stake' in form.fields) stakefield = form.fields['stake'] self.assertTrue((stake.pk, unicode(stake)) in stakefield.choices) self.client.logout() # Test for two structures s1 = StructureFactory.create() s2 = StructureFactory.create() st1 = StakeFactory.create(structure=s1) StakeFactory.create(structure=s1) st2 = StakeFactory.create(structure=s2) StakeFactory.create(structure=s2) test_structure(s1, st1) test_structure(s2, st2)
def test_set_structure_with_permission_object_linked_none_structure(self): if not hasattr(self.model, 'structure'): return self.login() perm = Permission.objects.get(codename='can_bypass_structure') self.user.user_permissions.add(perm) structure = StructureFactory() st0 = StakeFactory.create(structure=None) self.assertNotEqual(structure, self.user.profile.structure) data = self.get_good_data() data['stake'] = st0.pk data['structure'] = self.user.profile.structure.pk response = self.client.post(self._get_add_url(), data) self.assertEqual(response.status_code, 302) obj = self.model.objects.last() self.assertEqual(obj.structure, self.user.profile.structure) self.logout()
def get_good_data(self): InterventionStatusFactory.create() good_data = { 'name': 'test', 'date': '2012-08-23', 'disorders': InterventionDisorderFactory.create().pk, 'comments': '', 'slope': 0, 'area': 0, 'subcontract_cost': 0.0, 'stake': StakeFactory.create().pk, 'height': 0.0, 'project': '', 'width': 0.0, 'length': 0.0, 'status': InterventionStatus.objects.all()[0].pk, 'heliport_cost': 0.0, 'material_cost': 0.0, 'manday_set-TOTAL_FORMS': '2', 'manday_set-INITIAL_FORMS': '0', 'manday_set-MAX_NUM_FORMS': '', 'manday_set-0-nb_days': '48.75', 'manday_set-0-job': InterventionJobFactory.create().pk, 'manday_set-0-id': '', 'manday_set-0-DELETE': '', 'manday_set-1-nb_days': '12', 'manday_set-1-job': InterventionJobFactory.create().pk, 'manday_set-1-id': '', 'manday_set-1-DELETE': '', } if settings.TREKKING_TOPOLOGY_ENABLED: path = PathFactory.create() good_data['topology'] = '{"paths": [%s]}' % path.pk, else: good_data['topology'] = 'SRID=4326;POINT (5.1 6.6)' return good_data