From ea29aa7d6bcb21c502f7cd544c2fef90dfb038e3 Mon Sep 17 00:00:00 2001 From: mpeltriaux Date: Thu, 27 Jan 2022 15:32:31 +0100 Subject: [PATCH] #31 API Tests * moves setupTestData in BaseAPITestCase class --- api/tests/v1/test_api_create.py | 31 +++++++++++++++++++++++++++++++ api/tests/v1/test_api_sharing.py | 18 ++---------------- 2 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 api/tests/v1/test_api_create.py diff --git a/api/tests/v1/test_api_create.py b/api/tests/v1/test_api_create.py new file mode 100644 index 00000000..175bc7fc --- /dev/null +++ b/api/tests/v1/test_api_create.py @@ -0,0 +1,31 @@ +""" +Author: Michel Peltriaux +Organization: Struktur- und Genehmigungsdirektion Nord, Rhineland-Palatinate, Germany +Contact: michel.peltriaux@sgdnord.rlp.de +Created on: 27.01.22 + +""" +from konova.settings import DEFAULT_GROUP +from konova.tests.test_views import BaseTestCase + + +class BaseAPIV1TestCase(BaseTestCase): + @classmethod + def setUpTestData(cls): + super().setUpTestData() + + cls.superuser.get_API_token() + cls.superuser.api_token.is_active = True + cls.superuser.api_token.save() + default_group = cls.groups.get(name=DEFAULT_GROUP) + cls.superuser.groups.add(default_group) + + cls.header_data = { + "HTTP_ksptoken": cls.superuser.api_token.token, + } + + +class APIV1CreateTestCase(BaseAPIV1TestCase): + @classmethod + def setUpTestData(cls): + super().setUpTestData() diff --git a/api/tests/v1/test_api_sharing.py b/api/tests/v1/test_api_sharing.py index df673e08..289a16b0 100644 --- a/api/tests/v1/test_api_sharing.py +++ b/api/tests/v1/test_api_sharing.py @@ -2,30 +2,16 @@ import json from django.urls import reverse +from api.tests.v1.test_api_create import BaseAPIV1TestCase from konova.settings import DEFAULT_GROUP -from konova.tests.test_views import BaseTestCase from konova.utils.user_checks import is_default_group_only -class APIV1SharingTestCase(BaseTestCase): +class APIV1SharingTestCase(BaseAPIV1TestCase): @classmethod def setUpTestData(cls): - """ Creates a test file in memory for using in further tests - - Returns: - - """ super().setUpTestData() - cls.superuser.get_API_token() - cls.superuser.api_token.is_active = True - cls.superuser.api_token.save() - default_group = cls.groups.get(name=DEFAULT_GROUP) - cls.superuser.groups.add(default_group) - - cls.header_data = { - "HTTP_ksptoken": cls.superuser.api_token.token, - } def _run_share_request(self, url, user_list: list): data = {