From 528b37caea341c4b1a4edd6ab38e10e93a96195e Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Tue, 25 Sep 2018 09:56:50 -0500
Subject: [PATCH] Moving test utility from API base to generic base

Moved request_as_user from GraceDbApiTestBase to GraceDbTestBase
so that it can be used in tests for other apps.
---
 gracedb/api/tests/utils.py  | 25 -------------------------
 gracedb/core/tests/utils.py | 32 ++++++++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/gracedb/api/tests/utils.py b/gracedb/api/tests/utils.py
index de7ae39f4..231aa4d9e 100644
--- a/gracedb/api/tests/utils.py
+++ b/gracedb/api/tests/utils.py
@@ -5,28 +5,3 @@ from core.tests.utils import GraceDbTestBase
 
 class GraceDbApiTestBase(GraceDbTestBase):
     client_class = APIClient
-
-    def request_as_user(self, url, method, user=None, data=None, **kwargs):
-        """Shortcut function for making a request to the API"""
-        # Get client method for HTTP method requested
-        try:
-            method_func = getattr(self.client, method.lower())
-        except Exception as e:
-            raise ValueError('{method} is not a valid HTTP method'.format(
-                method=method))
-
-        if user is not None:
-            # Set up user dict
-            user_dict = {
-                'HTTP_REMOTE_USER': user.username,
-                'HTTP_ISMEMBEROF': ';'.join([g.name for g in
-                    user.groups.all()]),
-            }
-            if kwargs:
-                user_dict.update(**kwargs)
-
-            # Make request and return response
-            return method_func(url, data, **user_dict)
-        else:
-            # Anonymous user
-            return method_func(url, data)
diff --git a/gracedb/core/tests/utils.py b/gracedb/core/tests/utils.py
index 126ab8777..00d2483af 100644
--- a/gracedb/core/tests/utils.py
+++ b/gracedb/core/tests/utils.py
@@ -272,5 +272,33 @@ class PublicGroupSetup(TestCase):
 
 class GraceDbTestBase(DefineTestSettings, InternalGroupAndUserSetup,
     LvemGroupAndUserSetup, PublicGroupSetup):
-    """Combines all test base classes"""
-    pass
+    """
+    Combines all test base classes and defines method for easily making
+    requests with a specfic user account.
+    """
+
+    def request_as_user(self, url, method, user=None, data=None, **kwargs):
+        """Shortcut function for making a request"""
+        # Get client method for HTTP method requested
+        try:
+            method_func = getattr(self.client, method.lower())
+        except Exception as e:
+            raise ValueError('{method} is not a valid HTTP method'.format(
+                method=method))
+
+        if user is not None:
+            # Set up user dict
+            user_dict = {
+                'HTTP_REMOTE_USER': user.username,
+                'HTTP_ISMEMBEROF': ';'.join([g.name for g in
+                    user.groups.all()]),
+            }
+            if kwargs:
+                user_dict.update(**kwargs)
+
+            # Make request and return response
+            return method_func(url, data, **user_dict)
+        else:
+            # Anonymous user
+            return method_func(url, data)
+
-- 
GitLab