[damned-lies] Add more precise anonymous testing in API tests
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Add more precise anonymous testing in API tests
- Date: Tue, 6 Apr 2021 07:32:52 +0000 (UTC)
commit 5932d70492f5265c701156d1dd520ec0fd799efb
Author: Claude Paroz <claude 2xlibre net>
Date: Tue Apr 6 09:24:00 2021 +0200
Add more precise anonymous testing in API tests
api/tests.py | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/api/tests.py b/api/tests.py
index 5997098b..904501f5 100644
--- a/api/tests.py
+++ b/api/tests.py
@@ -111,8 +111,10 @@ class APITests(TestCase):
)
Role.objects.create(team=Team.objects.get(name='fr'), person=translator)
url = reverse('api-reserve', args=['gnome-hello', 'master', 'po', 'fr'])
+ # Test anonymous cannot post
response = self.client.post(url, data={})
- self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, reverse('login') + f'?next={url}')
+
self.client.force_login(translator)
response = self.client.post(url, data={})
self.assertEqual(response.json(), {'result': 'OK'})
@@ -132,9 +134,10 @@ class APITests(TestCase):
)
url = reverse('api-upload', args=['gnome-hello', 'master', 'po', 'fr'])
test_po = Path(__file__).parent.parent / "stats" / "tests" / "test.po"
+ # Test anonymous cannot post
with (test_po).open('rb') as fh:
response = self.client.post(url, data={'file': File(fh)})
- self.assertEqual(response.status_code, 302)
+ self.assertRedirects(response, reverse('login') + f'?next={url}')
self.client.force_login(translator)
with (test_po).open('rb') as fh:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]