From 10eb7d49b23d0ef9b1f3accb024fbeab63518ba7 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 4 Feb 2016 17:39:27 -0400 Subject: [PATCH] Update API tests to use login instead of force_authenticate. --- mayan/apps/authentication/tests/test_views.py | 9 ++++++--- mayan/apps/documents/tests/test_api.py | 14 +++++++++----- mayan/apps/dynamic_search/tests/test_api.py | 4 +++- mayan/apps/folders/tests/test_api.py | 4 +++- mayan/apps/ocr/tests/test_api.py | 4 +++- mayan/apps/tags/tests/test_api.py | 4 +++- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/mayan/apps/authentication/tests/test_views.py b/mayan/apps/authentication/tests/test_views.py index 8c02c02ee4..314e5ba43a 100644 --- a/mayan/apps/authentication/tests/test_views.py +++ b/mayan/apps/authentication/tests/test_views.py @@ -29,7 +29,8 @@ class UserLoginTestCase(TestCase): def test_normal_behaviour(self): response = self.client.get(reverse('documents:document_list')) self.assertRedirects( - response, 'http://testserver/authentication/login/' + response, + 'http://testserver/authentication/login/?next=/documents/list/' ) @override_settings(AUTHENTICATION_LOGIN_METHOD='username') @@ -63,7 +64,8 @@ class UserLoginTestCase(TestCase): def test_username_login_via_views(self): response = self.client.get(reverse('documents:document_list')) self.assertRedirects( - response, 'http://testserver/authentication/login/' + response, + 'http://testserver/authentication/login/?next=/documents/list/' ) response = self.client.post( @@ -81,7 +83,8 @@ class UserLoginTestCase(TestCase): with self.settings(AUTHENTICATION_BACKENDS=(TEST_EMAIL_AUTHENTICATION_BACKEND,)): response = self.client.get(reverse('documents:document_list')) self.assertRedirects( - response, 'http://testserver/authentication/login/' + response, + 'http://testserver/authentication/login/?next=/documents/list/' ) response = self.client.post( diff --git a/mayan/apps/documents/tests/test_api.py b/mayan/apps/documents/tests/test_api.py index 9f0c1e50fd..6763518c05 100644 --- a/mayan/apps/documents/tests/test_api.py +++ b/mayan/apps/documents/tests/test_api.py @@ -38,7 +38,9 @@ class DocumentTypeAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) def tearDown(self): self.admin_user.delete() @@ -101,7 +103,9 @@ class DocumentAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE @@ -113,17 +117,17 @@ class DocumentAPITestCase(APITestCase): def test_document_upload(self): with open(TEST_DOCUMENT_PATH) as file_descriptor: - document_response = self.client.post( + response = self.client.post( reverse('rest_api:document-list'), { 'document_type': self.document_type.pk, 'file': file_descriptor } ) - document_data = loads(document_response.content) + document_data = loads(response.content) self.assertEqual( - document_response.status_code, status.HTTP_201_CREATED + response.status_code, status.HTTP_201_CREATED ) self.assertEqual(Document.objects.count(), 1) diff --git a/mayan/apps/dynamic_search/tests/test_api.py b/mayan/apps/dynamic_search/tests/test_api.py index 632a240ea6..df087c2178 100644 --- a/mayan/apps/dynamic_search/tests/test_api.py +++ b/mayan/apps/dynamic_search/tests/test_api.py @@ -28,7 +28,9 @@ class SearchAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) def test_search(self): document_type = DocumentType.objects.create( diff --git a/mayan/apps/folders/tests/test_api.py b/mayan/apps/folders/tests/test_api.py index b3e75e2999..2f97f574b8 100644 --- a/mayan/apps/folders/tests/test_api.py +++ b/mayan/apps/folders/tests/test_api.py @@ -29,7 +29,9 @@ class FolderAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) def test_folder_create(self): self.client.post( diff --git a/mayan/apps/ocr/tests/test_api.py b/mayan/apps/ocr/tests/test_api.py index 11855f280b..e6649853df 100644 --- a/mayan/apps/ocr/tests/test_api.py +++ b/mayan/apps/ocr/tests/test_api.py @@ -27,7 +27,9 @@ class OCRAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) self.document_type = DocumentType.objects.create( label=TEST_DOCUMENT_TYPE diff --git a/mayan/apps/tags/tests/test_api.py b/mayan/apps/tags/tests/test_api.py index 73ec5b9f14..679d5560cb 100644 --- a/mayan/apps/tags/tests/test_api.py +++ b/mayan/apps/tags/tests/test_api.py @@ -32,7 +32,9 @@ class TagAPITestCase(APITestCase): password=TEST_ADMIN_PASSWORD ) - self.client.force_authenticate(user=self.admin_user) + self.client.login( + username=TEST_ADMIN_USERNAME, password=TEST_ADMIN_PASSWORD + ) def tearDown(self): self.admin_user.delete()