def test_structure_is_not_changed_with_permission_error(self): self.login() perm = Permission.objects.get(codename='can_bypass_structure') self.user.user_permissions.add(perm) structure = StructureFactory() structure_2 = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) obj = self.modelfactory.create(structure=structure) data = self.get_good_data() data['structure'] = structure_2.pk result = self.client.post(obj.get_update_url(), data) self.assertEqual(result.status_code, 200) self.assertIn("Please select a choice related to all structures", result.content) self.logout()
def test_structure_is_not_changed_with_permission_error(self): self.login() perm = Permission.objects.get(codename='can_bypass_structure') self.user.user_permissions.add(perm) structure = StructureFactory() structure_2 = StructureFactory() source = PathSource.objects.create(source="Source_1", structure=structure) self.assertNotEqual(structure, self.user.profile.structure) obj = self.modelfactory.create(structure=structure) data = self.get_good_data().copy() data['source'] = source.pk data['structure'] = structure_2.pk response = self.client.post(obj.get_update_url(), data) self.assertContains(response, "Please select a choice related to all structures") self.logout()
def test_signage_type_change_not_same_structure(self): self.login() structure = StructureFactory(name="Other") signagetype = SignageTypeFactory.create(structure=structure) change_url = reverse('admin:signage_signagetype_change', args=[signagetype.pk]) response = self.client.get(change_url) self.assertEqual(response.status_code, 200) self.assertContains(response, '<select name="structure" id="id_structure">')
def test_merge_works_wrong_structure(self): self.login() other_structure = StructureFactory(name="Other") p1 = PathFactory.create(name="AB", geom=LineString((0, 0), (1, 0))) p2 = PathFactory.create(name="BC", geom=LineString((1, 0), (2, 0)), structure=other_structure) response = self.client.post(reverse('core:merge_path'), {'path[]': [p1.pk, p2.pk]}) self.assertEqual({'error': "You don't have the right to change these paths"}, response.json()) self.logout()
def test_structure_is_not_changed_without_permission(self): self.login() structure = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) self.assertFalse(self.user.has_perm('authent.can_bypass_structure')) obj = self.modelfactory.create(structure=structure) self.client.post(obj.get_update_url(), self.get_good_data()) self.assertEqual(obj.structure, structure)
def test_sealing_change_not_same_structure(self): self.login() structure = StructureFactory(name="Other") sealing = SealingFactory.create(structure=structure) change_url = reverse('admin:signage_sealing_change', args=[sealing.pk]) response = self.client.get(change_url) self.assertEquals(response.status_code, 200) self.assertIn('<select name="structure" id="id_structure">', response.content)
def test_structure_is_not_changed(self): if not hasattr(self.model, 'structure'): return self.login() structure = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) obj = self.modelfactory.create(structure=structure) self.client.post(obj.get_update_url(), self.get_good_data()) self.assertEqual(obj.structure, structure)
def test_bladetype_change_not_same_structure(self): self.login() structure = StructureFactory(name="Other") bladetype = BladeTypeFactory.create(structure=structure) change_url = reverse('admin:signage_bladetype_change', args=[bladetype.pk]) response = self.client.get(change_url) self.assertEqual(response.status_code, 302) self.assertEqual(BladeType.objects.get(pk=self.bladetype.pk).label, self.bladetype.label) self.assertEqual(response.url, '/admin/')
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.assertEqual(response.status_code, 302) self.assertEqual(InfrastructureType.objects.get(pk=self.infra.pk).label, self.infra.label) self.assertEqual(response.url, '/admin/')
def test_structure_is_not_changed_without_permission(self): self.login() structure = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) self.assertFalse(self.user.has_perm('authent.can_bypass_structure')) obj = self.modelfactory.create(signage__structure=structure) result = self.client.post(obj.get_update_url(), self.get_good_data()) self.assertEqual(result.status_code, 302) self.assertEqual(self.model.objects.first().structure, structure) self.logout()
def test_delete_view_multiple_path_one_wrong_structure(self): other_structure = StructureFactory(name="Other") path_1 = PathFactory.create(name="path_1", geom=LineString((0, 0), (4, 0))) path_2 = PathFactory.create(name="path_2", geom=LineString((2, 2), (2, -2)), structure=other_structure) POIFactory.create(paths=[(path_1, 0, 0)]) response = self.client.get(reverse('core:multiple_path_delete', args=['%s,%s' % (path_1.pk, path_2.pk)])) self.assertEqual(response.status_code, 302) self.assertEqual(response.url, reverse('core:path_list')) self.assertIn(response.content, b'Access to the requested resource is restricted by structure.') self.assertEqual(Path.objects.count(), 4)
def test_sealing_change_not_same_structure(self): self.login() structure = StructureFactory(name="Other") sealing = SealingFactory.create(structure=structure) change_url = reverse('admin:signage_sealing_change', args=[sealing.pk]) response = self.client.get(change_url) self.assertEqual(response.status_code, 302) self.assertEqual(Sealing.objects.get(pk=self.sealing.pk).label, self.sealing.label) self.assertEqual(response.url, '/admin/')
def setUp(self): self.user = UserFactory.create(password='******') self.client.login(username=self.user.username, password='******') 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.sealing = SealingFactory.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 = InfrastructureConditionFactory.create(structure=structure)
def test_structure_is_changed_with_permission(self): self.login() perm = Permission.objects.get(codename='can_bypass_structure') self.user.user_permissions.add(perm) structure = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) obj = self.modelfactory.create() data = self.get_good_data() data['structure'] = structure result = self.client.post(obj.get_update_url(), data) self.assertEqual(result.status_code, 302) self.assertEqual(self.model.objects.first().structure, self.user.profile.structure) self.logout()
def test_set_structure_with_permission(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() self.assertNotEqual(structure, self.user.profile.structure) data = self.get_good_data() 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 test_structure_restricted(self): p = PathFactory() # Login user = PathManagerFactory(password="******") success = self.client.login(username=user.username, password="******") self.assertTrue(success) # Try to edit path from same structure response = self.client.get(p.get_update_url()) self.assertEqual(response.status_code, 200) # Try to edit path from other structure p.structure = StructureFactory(name="Other") p.save() self.assertNotEqual(p.structure, user.profile.structure) response = self.client.get(p.get_update_url()) self.assertEqual(response.status_code, 302)
def test_set_structure_with_permission(self): # The structure do not change because it changes with the signage form. # Need to check blade structure and line self.login() perm = Permission.objects.get(codename='can_bypass_structure') self.user.user_permissions.add(perm) structure = StructureFactory() self.assertNotEqual(structure, self.user.profile.structure) signage = SignageFactory(structure=structure) data = self.get_good_data() data['signage'] = signage.pk data['structure'] = self.user.profile.structure.pk response = self.client.post('%s?signage=%s' % (Blade.get_add_url(), signage.pk), data) self.assertEqual(response.status_code, 302) obj = self.model.objects.last() self.assertEqual(obj.structure, structure) self.logout()
def test_basic(self): s = StructureFactory(name="Mércäntour") self.assertEqual(str(s), "Mércäntour")
def test_basic(self): s = StructureFactory(name=u"Mércäntour") self.assertEqual(unicode(s), u"Mércäntour")