def test_manager(self): it1 = InfrastructureTypeFactory.create() it2 = InfrastructureTypeFactory.create() it3 = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE) self.assertNotEqual(InfrastructureType.objects.for_signages(), InfrastructureType.objects.for_infrastructures()) self.assertItemsEqual(InfrastructureType.objects.for_signages(), [it3]) self.assertItemsEqual(InfrastructureType.objects.for_infrastructures(), [it1, it2]) self.assertItemsEqual(InfrastructureType.objects.all(), [it1, it2, it3])
def get_good_data(self): PathFactory.create() return { "name": "test", "description": "oh", "structure": default_structure().pk, "type": InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk, "topology": '{"lat": 0.42, "lng": 0.666}', }
def get_good_data(self): path = PathFactory.create() return { 'name': 'test', 'description': 'oh', 'structure': default_structure().pk, 'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk, 'topology': '{"paths": [%s]}' % path.pk, }
def get_good_data(self): PathFactory.create() return { 'name': 'test', 'description': 'oh', 'structure': default_structure().pk, 'type': InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk, 'topology': '{"lat": 0.42, "lng": 0.666}' }
def test_check_structure_or_none_related_are_visible(self): self.login() infratype = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING, structure=None) response = self.client.get(self.model.get_add_url()) self.assertEqual(response.status_code, 200) self.assertTrue('form' in response.context) form = response.context['form'] type = form.fields['type'] self.assertTrue((infratype.pk, unicode(infratype)) in type.choices)
def get_good_data(self): path = PathFactory.create() return { "name": "test", "description": "oh", "structure": default_structure().pk, "type": InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.BUILDING).pk, "topology": '{"paths": [%s]}' % path.pk, }
def test_infrastructuretype_cannot_be_change_not_same_structure(self): self.login() structure = StructureFactory(name="Other") infra = InfrastructureTypeFactory.create(structure=structure) change_url = reverse('admin:infrastructure_infrastructuretype_change', args=[infra.pk]) response = self.client.get(change_url) self.assertEquals(response.status_code, 302) self.assertEqual(InfrastructureType.objects.get(pk=self.infra.pk).label, self.infra.label) self.assertEqual(response.url, '/admin/')
def test_command_unset_structure(self): structure1 = StructureFactory.create(name="coucou") structure2 = StructureFactory.create(name="coco") infratype1 = InfrastructureTypeFactory.create(label="annyeong", structure=structure1, pictogram=None) infratype2 = InfrastructureTypeFactory.create(label="annyeong", structure=structure2, pictogram=None) path = PathFactory.create(name="pass") usage1 = UsageFactory.create(usage="hello", structure=structure1) usage2 = UsageFactory.create(usage="hello", structure=structure2) path.usages.add(usage1) path.usages.add(usage2) infrastructure1 = InfrastructureFactory.create(name='pissenlit', type=infratype1) infrastructure2 = InfrastructureFactory.create(name='rhododendron', type=infratype2) self.assertEqual(InfrastructureType.objects.count(), 2) self.assertEqual(Usage.objects.count(), 2) self.assertEqual(infrastructure1.type.label, 'annyeong') self.assertEqual(infrastructure1.type.structure.name, 'coucou') self.assertEqual(infrastructure2.type.label, 'annyeong') self.assertEqual(infrastructure2.type.structure.name, 'coco') self.assertEqual(path.usages.count(), 2) self.assertEqual(usage1.structure.name, 'coucou') self.assertEqual(usage2.structure.name, 'coco') output = StringIO() call_command('unset_structure', '--all', verbosity=2, stdout=output) response = output.getvalue() self.assertIn("Create hello", response) self.assertEqual(InfrastructureType.objects.count(), 1) self.assertEqual(Usage.objects.count(), 1) infra = Infrastructure.objects.first() self.assertEqual(infra.type.label, 'annyeong') self.assertEqual(infra.type.structure, None) path_usages = Path.objects.first().usages.first() self.assertEqual(path_usages.usage, 'hello') self.assertEqual(path_usages.structure, None)
def setUp(self): self.user = UserFactory.create(password='******') self.client.login(username=self.user.username, password='******') self.user.user_permissions.add(Permission.objects.get(codename='add_draft_path')) for perm in Permission.objects.exclude(codename='can_bypass_structure'): self.user.user_permissions.add(perm) self.user.is_staff = True self.user.save() p = self.user.profile structure = StructureFactory(name="This") p.structure = structure p.save() self.infra = InfrastructureTypeFactory.create(structure=structure)
def setUp(self): self.user = UserFactory.create(password='******') self.client.login(username=self.user.username, password='******') self.user.user_permissions.add( Permission.objects.get(codename='add_draft_path')) for perm in Permission.objects.exclude( codename='can_bypass_structure'): self.user.user_permissions.add(perm) self.user.is_staff = True self.user.save() p = self.user.profile structure = StructureFactory(name="This") p.structure = structure p.save() self.infra = InfrastructureTypeFactory.create(structure=structure)
def get_good_data(self): PathFactory.create() return { 'name': 'test', 'description': 'oh', 'type': InfrastructureTypeFactory.create( type=INFRASTRUCTURE_TYPES.BUILDING).pk, 'condition': InfrastructureConditionFactory.create().pk, 'topology': '{"lat": 0.42, "lng": 0.666}' }
def get_good_data(self): path = PathFactory.create() return { 'name': 'test', 'description': 'oh', 'type': InfrastructureTypeFactory.create( type=INFRASTRUCTURE_TYPES.BUILDING).pk, 'condition': InfrastructureConditionFactory.create().pk, 'topology': '{"paths": [%s]}' % path.pk, }
def get_good_data(self): good_data = { 'name': 'test', 'description': 'oh', 'type': InfrastructureTypeFactory.create( type=INFRASTRUCTURE_TYPES.BUILDING).pk, 'condition': InfrastructureConditionFactory.create().pk, } if settings.TREKKING_TOPOLOGY_ENABLED: path = PathFactory.create() good_data['topology'] = '{"paths": [%s]}' % path.pk else: good_data['geom'] = 'LINESTRING (0.0 0.0, 1.0 1.0)' return good_data
def get_good_data(self): data = super(SignageViewsTest, self).get_good_data() data['type'] = InfrastructureTypeFactory.create(type=INFRASTRUCTURE_TYPES.SIGNAGE).pk data['condition'] = InfrastructureConditionFactory.create().pk return data
def setUp(self): self.user = SuperUserFactory.create(password='******') self.infra = InfrastructureTypeFactory.create()
def test_unset_structure_without_structure(self): infratype = InfrastructureTypeFactory.create(label="annyeong", structure=None, pictogram=None) self.assertEqual(InfrastructureType.objects.count(), 1) self.assertIsNone(infratype.structure) call_command('unset_structure', '--all', verbosity=0) self.assertIsNone(infratype.structure)
def test_unset_structure_fail_no_model_not_all(self): InfrastructureTypeFactory.create(label="annyeong", structure=None, pictogram=None) with self.assertRaisesRegexp(CommandError, "You should specify model"): call_command('unset_structure', verbosity=0)