def test_intervention_filter(self): model = self.factory._associated_class user = PathManagerFactory(password='******') success = self.client.login(username=user.username, password='******') self.assertTrue(success) # We will filter by this year year_idx, year = self.filterset.declared_filters[ 'intervention_year'].get_choices()[1] good_date_year = datetime.datetime(year=year, month=2, day=2) bad_date_year = datetime.datetime(year=year + 2, month=2, day=2) # Bad topology/infrastructure: No intervention self.factory() # Bad signage: intervention with wrong year bad_topo = self.factory() InterventionFactory(topology=bad_topo, date=bad_date_year) # Good signage: intervention with the good year good_topo = self.factory() InterventionFactory(topology=good_topo, date=good_date_year) data = {'intervention_year': year_idx} response = self.client.get(model.get_jsonlist_url(), data) self.assertEqual(response.status_code, 200) topo_pk = json.loads(response.content)['map_obj_pk'] self.assertItemsEqual(topo_pk, [good_topo.pk])
def test_paths_bystructure(self): PathFactory(length=1) PathFactory(length=70) password = '******' user = PathManagerFactory(password=password) result = self.client.login(username=user.username, password=password) self.assertTrue(result, u"The client successfully logged in") response = self.client.get(reverse('core:path_list')) self.assertEquals(response.status_code, 200) def create_form_params(range_start='', range_end=''): """Return range form parameter as used in geotrek.core.filters.PathFilter""" return { 'length_0': range_end, 'length_1': range_start } def test_response_content(length_range, queryset): response = self.client.get(reverse('core:path_json_list'), data=create_form_params(*length_range)) self.assertEquals(response.status_code, 200) # We check the 'map_obj_pk' json attribute that should contain the paths' pk (used by map) jsondict = json.loads(response.content) # The JSON should only contain filtered paths self.assertListEqual( sorted(jsondict['map_obj_pk']), sorted(list(queryset.values_list('pk', flat=True))), ) # Simulate ajax call to populate the list # The path returned as json should be all paths test_response_content(['', ''], Path.objects.all()) # Simulate ajax call to populate the list, but this time with a range filter length_range = [50, 100] test_response_content(length_range, Path.objects.filter(length__range=length_range))
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_path_manager_restricted(self): p = PathFactory() # Try to edit path as user user = UserFactory(password="******") self.assertFalse(user.profile.is_path_manager) success = self.client.login(username=user.username, password="******") self.assertTrue(success) response = self.client.get(p.get_update_url()) self.assertEqual(response.status_code, 302) self.client.logout() # Try to edit path as manager manager = PathManagerFactory(password="******") self.assertTrue(manager.profile.is_path_manager) success = self.client.login(username=manager.username, password="******") self.assertTrue(success) response = self.client.get(p.get_update_url()) self.assertEqual(response.status_code, 200)
def login(self): user = PathManagerFactory(password='******') success = self.client.login(username=user.username, password='******') self.assertTrue(success)
def setUp(self): self.user = PathManagerFactory.create(password='******') self.stake = StakeFactory.create()
def login(self): self.user = PathManagerFactory.create(password='******') success = self.client.login(username=self.user.username, password='******') self.assertTrue(success)
def setUp(self): self.password = '******' self.user = PathManagerFactory(password=self.password) self.assertTrue( self.client.login(username=self.user.username, password=self.password))