You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2022/10/20 22:27:03 UTC

[airavata-django-portal] 04/04: AIRAVATA-3647 Unit test for handling unauthenticated REST error responses

This is an automated email from the ASF dual-hosted git repository.

machristie pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit d12ad44a0d1f5615882429d86b5eb9134c20ce83
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Thu Oct 20 18:23:49 2022 -0400

    AIRAVATA-3647 Unit test for handling unauthenticated REST error responses
---
 django_airavata/apps/api/tests/test_views.py | 23 +++++++++++++++++++++++
 tests/settings.py                            |  5 ++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/django_airavata/apps/api/tests/test_views.py b/django_airavata/apps/api/tests/test_views.py
index 22d30e79..201538dc 100644
--- a/django_airavata/apps/api/tests/test_views.py
+++ b/django_airavata/apps/api/tests/test_views.py
@@ -468,3 +468,26 @@ class IAMUserViewSetTests(TestCase):
         group_manager_mock.getGroup.assert_not_called()
         group_manager_mock.addUsersToGroup.assert_not_called()
         user_added_to_group_handler.assert_not_called()
+
+
+@override_settings(
+    GATEWAY_ID=GATEWAY_ID,
+    PORTAL_ADMINS=PORTAL_ADMINS
+)
+class ExceptionHandlingTest(TestCase):
+
+    def setUp(self):
+        self.user = User.objects.create_user('testuser')
+        self.factory = APIRequestFactory()
+
+    def test_unauthenticated_request(self):
+
+        url = reverse('django_airavata_api:group-list')
+        data = {}
+        request = self.factory.post(url, data)
+        # Deliberately not authenticating user for request
+        group_create = views.GroupViewSet.as_view({'post': 'create'})
+        response = group_create(request)
+        self.assertEquals(403, response.status_code)
+        self.assertIn('is_authenticated', response.data)
+        self.assertFalse(response.data['is_authenticated'])
diff --git a/tests/settings.py b/tests/settings.py
index 7bc12f00..e65a3bcd 100644
--- a/tests/settings.py
+++ b/tests/settings.py
@@ -10,7 +10,10 @@ BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': os.path.join(BASEDIR, 'db.sqlite3'),
+        'TEST': {
+            'ENGINE': 'django.db.backends.sqlite3',
+            'NAME': os.path.join(BASEDIR, 'test-db.sqlite3'),
+        }
     }
 }