From 364d678f720679d55ae60c7cb4e3790f8b95d436 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Tue, 10 Feb 2015 18:22:01 +0100 Subject: Archaeological tests: fix REST test by adding authentification --- archaeological_files/tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'archaeological_files/tests.py') diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index b4ad7d4b5..b30c39dc1 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -36,9 +36,15 @@ class FileTest(TestCase): '../ishtar_common/fixtures/initial_data-fr.json'] model = models.File + def login_as_superuser(self): + self.client.login(username='username', password='tralala') + def setUp(self): self.extra_models, self.model_list = {}, [] - self.user, created = User.objects.get_or_create(username='username') + self.user, created = User.objects.get_or_create(username='username', + is_superuser=True) + self.user.set_password('tralala') + self.user.save() self.o_user, created = User.objects.get_or_create(username='ousername') person_type = PersonType(label=u'Test person type', txt_idx='test_person', available=True) @@ -132,6 +138,14 @@ class FileTest(TestCase): unicode(initial_values[k]))) def testRESTGetFile(self): + response = self.client.post('/get-file/', + {'numeric_reference':self.item.numeric_reference}) + self.assertEqual(response.status_code, 200) + data = json.loads(response.content) + # not allowed -> no data + self.assertTrue(not data) + + self.login_as_superuser() response = self.client.post('/get-file/', {'numeric_reference':self.item.numeric_reference}) self.assertEqual(response.status_code, 200) @@ -150,6 +164,14 @@ class FileTest(TestCase): {'numeric_reference':self.item.numeric_reference, 'old':1}) self.assertEqual(response.status_code, 200) data = json.loads(response.content) + # not allowed -> no data + self.assertTrue(not data) + + self.login_as_superuser() + response = self.client.post('/get-file/', + {'numeric_reference':self.item.numeric_reference, 'old':1}) + self.assertEqual(response.status_code, 200) + data = json.loads(response.content) self.assertTrue('records' in data) self.assertTrue(data['records'] == 1) self.assertEqual(data['rows'][0]['internal_reference'], initial_ref) -- cgit v1.2.3