Skip to content
Snippets Groups Projects
Commit 799382cb authored by Kenzo-Hugo Hillion's avatar Kenzo-Hugo Hillion :recycle:
Browse files

refacto base for tests as admin

parent 23929d48
No related branches found
No related tags found
2 merge requests!59Prod,!24Use permissions and auth
Pipeline #19418 failed
from django.contrib.auth.models import User
from requests.exceptions import HTTPError
from rest_framework.test import APITestCase
from rest_framework_jwt.settings import api_settings
from metagenedb.apps.catalog.factory import FunctionFactory
from metagenedb.common.utils.mocks.metagenedb import MetageneDBCatalogFunctionAPIMock
from metagenedb.common.utils.tests.apitestbase import AdminUserBasedTest
class TestOperationsBulkViewSetNoCredentials(APITestCase):
......@@ -32,7 +31,7 @@ class TestOperationsBulkViewSetNoCredentials(APITestCase):
self.function_api.put(data, function.function_id)
class TestOperationsBulkViewSet(APITestCase):
class TestOperationsBulkViewSet(AdminUserBasedTest):
"""
We are testing the different functions through the API directly through the mock redirecting
requests to the test database.
......@@ -41,15 +40,8 @@ class TestOperationsBulkViewSet(APITestCase):
"""
def setUp(self):
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
user = User.objects.create_user(username='user_admin', email='user@admin.com', password='pass')
user.is_active = True
user.is_staff = True
user.save()
payload = jwt_payload_handler(user)
jwt_token = jwt_encode_handler(payload)
self.function_api = MetageneDBCatalogFunctionAPIMock(self.client, jwt_token=jwt_token)
super().setUp()
self.function_api = MetageneDBCatalogFunctionAPIMock(self.client, jwt_token=self.jwt_token)
def test_create_function(self):
data = {
......
......@@ -20,24 +20,6 @@ class TestGenes(TestCase):
resp = self.client.get(url)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
def test_get_genes_auth(self):
"""
Authenticated users should be able to access genes
"""
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
user = User.objects.create_user(username='user', email='user@foo.com', password='pass')
user.is_active = True
user.save()
payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)
url = reverse('api:catalog:v1:genes-list')
resp = self.client.get(url, format='json', HTTP_AUTHORIZATION=f"JWT {token}")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
class TestCountWindowsAPI(APITestCase):
......
from django.contrib.auth.models import User
from rest_framework.test import APITestCase
from rest_framework_jwt.settings import api_settings
class AdminUserBasedTest(APITestCase):
"""
We are testing the different functions through the API directly through the mock redirecting
requests to the test database.
The extent is a bit more than a unittest since it is not just involving concerned methods.
"""
def setUp(self):
jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER
user = User.objects.create_user(username='user_admin', email='user@admin.com', password='pass')
user.is_active = True
user.is_staff = True
user.save()
payload = jwt_payload_handler(user)
self.jwt_token = jwt_encode_handler(payload)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment