test: Refactor all ViewSet Unit Test cases to use new test cases class
ref: #696 closes #672
This commit is contained in:
@ -1,61 +0,0 @@
|
||||
from django.contrib.auth.models import User
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from api.tests.abstract.viewsets import ViewSetCommon
|
||||
|
||||
from itim.viewsets.index import Index
|
||||
|
||||
|
||||
|
||||
class SettingsViewset(
|
||||
TestCase,
|
||||
ViewSetCommon
|
||||
):
|
||||
|
||||
viewset = Index
|
||||
|
||||
route_name = 'v2:_api_v2_settings_home'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_add", password="password", is_superuser=True)
|
||||
|
||||
|
||||
client = Client()
|
||||
url = reverse(self.route_name + '-list')
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
self.http_options_response_list = client.options(url)
|
||||
|
||||
self.kwargs = {}
|
||||
|
||||
|
||||
|
||||
def test_view_attr_permission_classes_value(self):
|
||||
"""Attribute Test
|
||||
|
||||
Attribute `permission_classes` must be metadata class `ReactUIMetadata`
|
||||
"""
|
||||
|
||||
view_set = self.viewset()
|
||||
|
||||
assert view_set.permission_classes[0] is IsAuthenticated
|
||||
|
||||
assert len(view_set.permission_classes) == 1
|
@ -1,51 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from api.tests.abstract.viewsets import ViewSetModel
|
||||
from api.tests.unit.test_unit_common_viewset import ModelRetrieveUpdateViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.app_settings import ViewSet
|
||||
|
||||
|
||||
|
||||
class ViewsetCommon(
|
||||
ViewSetModel,
|
||||
class AppSettingsViewsetList(
|
||||
ModelRetrieveUpdateViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_app_settings'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_view_user", password="password", is_superuser=True)
|
||||
|
||||
self.kwargs = {
|
||||
'pk': 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AppSettingsViewsetList(
|
||||
ViewsetCommon,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
@ -54,9 +25,12 @@ class AppSettingsViewsetList(
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.kwargs = {
|
||||
'pk': 1
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
|
@ -1,49 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from api.tests.abstract.viewsets import ViewSetModel
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.external_link import ViewSet
|
||||
|
||||
|
||||
|
||||
class ViewsetCommon(
|
||||
ViewSetModel,
|
||||
class ExternalLinksViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_external_link'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_view_user", password="password", is_superuser=True)
|
||||
|
||||
self.kwargs = {}
|
||||
|
||||
|
||||
|
||||
class ExternalLinksViewsetList(
|
||||
ViewsetCommon,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
@ -52,7 +25,6 @@ class ExternalLinksViewsetList(
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
|
@ -1,47 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from access.models.organization import Organization
|
||||
|
||||
from api.tests.abstract.viewsets import ViewSetModel
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.external_link_notes import ViewSet
|
||||
|
||||
|
||||
class ViewsetCommon(
|
||||
ViewSetModel,
|
||||
|
||||
class ExternalLinkNotesViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_external_link_note'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_view_user", password="password", is_superuser=True)
|
||||
|
||||
|
||||
|
||||
|
||||
class ExternalLinkNotesViewsetList(
|
||||
ViewsetCommon,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
|
36
app/settings/tests/unit/test_settings_viewset.py
Normal file
36
app/settings/tests/unit/test_settings_viewset.py
Normal file
@ -0,0 +1,36 @@
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import IndexViewsetInheritedCases
|
||||
|
||||
from itim.viewsets.index import Index
|
||||
|
||||
|
||||
|
||||
class SettingsViewset(
|
||||
IndexViewsetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = Index
|
||||
|
||||
route_name = 'v2:_api_v2_settings_home'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
client = Client()
|
||||
url = reverse(self.route_name + '-list')
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
self.http_options_response_list = client.options(url)
|
@ -1,52 +1,22 @@
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from access.models.organization import Organization
|
||||
from api.tests.unit.test_unit_common_viewset import ModelRetrieveUpdateViewSetInheritedCases
|
||||
|
||||
from api.tests.abstract.viewsets import ViewSetModel
|
||||
|
||||
from settings.models.app_settings import AppSettings
|
||||
from settings.viewsets.user_settings import ViewSet
|
||||
|
||||
|
||||
|
||||
class ViewsetCommon(
|
||||
ViewSetModel,
|
||||
class UserSettingsViewsetList(
|
||||
ModelRetrieveUpdateViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_v2_user_settings'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization
|
||||
3. create super user
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_view_user", password="password", is_superuser=True)
|
||||
|
||||
self.kwargs = {
|
||||
'pk': self.view_user.id
|
||||
}
|
||||
|
||||
|
||||
|
||||
class UserSettingsViewsetList(
|
||||
ViewsetCommon,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
@ -58,6 +28,10 @@ class UserSettingsViewsetList(
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.kwargs = {
|
||||
'pk': self.view_user.id
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
|
Reference in New Issue
Block a user