Compare commits
24 Commits
1b338e4c19
...
861bef0ce1
Author | SHA1 | Date | |
---|---|---|---|
861bef0ce1 | |||
3b86ab0e88 | |||
9f62e2a458 | |||
bd393e3dd4 | |||
9c73885f1b | |||
dbac9326b3 | |||
dd0a6a01b9 | |||
c294f9c8f5 | |||
71a510170d | |||
d577b12a33 | |||
fb090b6f63 | |||
75cda05579 | |||
97e63f1daa | |||
dce169109c | |||
4c6473a7b0 | |||
204a20b793 | |||
bf1a60439f | |||
006d7ab0c2 | |||
cca693d02d | |||
bb88a7025d | |||
8da10a147b | |||
653e29ffe5 | |||
b13610ef0e | |||
8739eba655 |
@ -1,94 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from access.serializers.organization import (
|
||||
Tenant,
|
||||
TenantModelSerializer
|
||||
)
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class OrganizationValidationAPI(
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = Tenant
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an org
|
||||
2. Create an item
|
||||
"""
|
||||
|
||||
self.user = User.objects.create(username = 'org_user', password='random password')
|
||||
|
||||
self.valid_data = {
|
||||
'name': 'valid_org_data',
|
||||
'manager': self.user.id
|
||||
}
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
name = 'random title',
|
||||
)
|
||||
|
||||
|
||||
|
||||
def test_serializer_valid_data(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
serializer = TenantModelSerializer(
|
||||
data = self.valid_data
|
||||
)
|
||||
|
||||
assert serializer.is_valid(raise_exception = True)
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_name(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
del data['name']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = TenantModelSerializer(
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_manager_optional(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
del data['manager']
|
||||
|
||||
serializer = TenantModelSerializer(
|
||||
data = data
|
||||
)
|
||||
|
||||
assert serializer.is_valid(raise_exception = True)
|
25
app/access/tests/functional/tenant/conftest.py
Normal file
25
app/access/tests/functional/tenant/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_tenant):
|
||||
|
||||
yield model_tenant
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_tenant):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_tenant.copy()
|
||||
|
||||
yield kwargs_tenant.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_tenant):
|
||||
|
||||
yield serializer_tenant
|
@ -0,0 +1,117 @@
|
||||
import pytest
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from django.db import models
|
||||
from django.test import Client
|
||||
|
||||
from api.tests.functional.test_functional_api_fields import (
|
||||
APIFieldsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_tenant
|
||||
class TenantAPITestCases(
|
||||
APIFieldsInheritedCases,
|
||||
):
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def make_request(self, django_db_blocker,
|
||||
request, organization_one,
|
||||
api_request_permissions,
|
||||
):
|
||||
|
||||
client = Client()
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
organization_one.manager = api_request_permissions['user']['view']
|
||||
organization_one.model_notes = 'sad'
|
||||
organization_one.save()
|
||||
|
||||
client.force_login( api_request_permissions['user']['view'] )
|
||||
response = client.get(
|
||||
organization_one.get_url()
|
||||
)
|
||||
|
||||
request.cls.api_data = response.data
|
||||
|
||||
|
||||
|
||||
item_two = getattr(request.cls, 'item_two', None)
|
||||
|
||||
if item_two:
|
||||
|
||||
response_two = client.get( self.item_two.get_url() )
|
||||
|
||||
request.cls.api_data_two = response_two.data
|
||||
|
||||
else:
|
||||
|
||||
request.cls.api_data_two = {}
|
||||
|
||||
|
||||
yield
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
organization_one.manager = None
|
||||
organization_one.model_notes = None
|
||||
organization_one.save()
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_api_fields(self):
|
||||
|
||||
return {
|
||||
'_urls.notes': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.id': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.display_name': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.url': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'name': {
|
||||
'expected': str
|
||||
},
|
||||
'manager': {
|
||||
'expected': dict
|
||||
},
|
||||
'manager.id': {
|
||||
'expected': int
|
||||
},
|
||||
'manager.display_name': {
|
||||
'expected': str
|
||||
},
|
||||
'manager.url': {
|
||||
'expected': Hyperlink
|
||||
},
|
||||
'modified': {
|
||||
'expected': str
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class TenantAPIInheritedCases(
|
||||
TenantAPITestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class TenantAPIPyTest(
|
||||
TenantAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_tenant
|
||||
class TenantModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class TenantModelInheritedCases(
|
||||
TenantModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class TenantModelPyTest(
|
||||
TenantModelTestCases,
|
||||
):
|
||||
pass
|
@ -16,6 +16,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_tenant
|
||||
class ViewSetBase:
|
||||
|
||||
model = Organization
|
||||
@ -191,16 +192,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class OrganizationViewSet(
|
||||
ViewSetBase,
|
||||
SerializersTestCases,
|
||||
TestCase
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class OrganizationMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctional,
|
@ -1,199 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import AnonymousUser, Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
|
||||
from api.tests.abstract.api_fields import APICommonFields
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class OrganizationAPI(
|
||||
TestCase,
|
||||
APICommonFields
|
||||
):
|
||||
|
||||
model = Organization
|
||||
|
||||
app_namespace = 'v2'
|
||||
|
||||
url_name = '_api_tenant'
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create the object
|
||||
2. create view user
|
||||
3. add user as org manager
|
||||
4. make api request
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org', model_notes='random text')
|
||||
|
||||
self.organization = organization
|
||||
|
||||
|
||||
self.item = organization
|
||||
|
||||
self.url_view_kwargs = {'pk': self.item.id}
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password")
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
organization.manager = self.view_user
|
||||
|
||||
organization.save()
|
||||
|
||||
|
||||
client = Client()
|
||||
url = reverse(self.app_namespace + ':' + self.url_name + '-detail', kwargs=self.url_view_kwargs)
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
response = client.get(url)
|
||||
|
||||
self.api_data = response.data
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
name field must exist
|
||||
"""
|
||||
|
||||
assert 'name' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['name']) is str
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_manager(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
manager field must exist
|
||||
"""
|
||||
|
||||
assert 'manager' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_manager(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
manager field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['manager']) is dict
|
||||
|
||||
|
||||
def test_api_field_exists_manager_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
manager.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['manager']
|
||||
|
||||
|
||||
def test_api_field_type_manager_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
manager.id field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['manager']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_manager_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
manager.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['manager']
|
||||
|
||||
|
||||
def test_api_field_type_manager_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
manager.display_name field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['manager']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_manager_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
manager.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['manager']
|
||||
|
||||
|
||||
def test_api_field_type_manager_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
manager.url field must be Hyperlink
|
||||
"""
|
||||
|
||||
assert type(self.api_data['manager']['url']) is Hyperlink
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_url_teams(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
_urls.teams field must exist
|
||||
"""
|
||||
|
||||
assert 'teams' in self.api_data['_urls']
|
||||
|
||||
|
||||
def test_api_field_type_url_teams(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
_urls.teams field must be Hyperlink
|
||||
"""
|
||||
|
||||
assert type(self.api_data['_urls']['teams']) is str
|
@ -1,18 +1,94 @@
|
||||
import pytest
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from api.tests.unit.test_unit_serializer import (
|
||||
SerializerTestCases
|
||||
)
|
||||
|
||||
|
||||
class TenantSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
pass
|
||||
from centurion.tests.abstract.mock_view import MockView
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_tenant
|
||||
class TenantSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def created_model(self, django_db_blocker, model, model_kwargs):
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = model.objects.create( **model_kwargs )
|
||||
|
||||
yield item
|
||||
|
||||
item.delete()
|
||||
|
||||
|
||||
def test_serializer_validation_no_name(self,
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
kwargs = kwargs_api_create.copy()
|
||||
del kwargs['name']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_manager_optional(self,
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
kwargs = kwargs_api_create.copy()
|
||||
del kwargs['manager']
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs
|
||||
)
|
||||
|
||||
assert serializer.is_valid(raise_exception = True)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class TenantSerializerPyTest(
|
||||
TenantSerializerTestCases
|
||||
|
25
app/settings/tests/functional/app_settings/conftest.py
Normal file
25
app/settings/tests/functional/app_settings/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_appsettings):
|
||||
|
||||
yield model_appsettings
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_appsettings):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_appsettings.copy()
|
||||
|
||||
yield kwargs_appsettings.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_appsettings):
|
||||
|
||||
yield serializer_appsettings
|
@ -0,0 +1,155 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
from django.test import Client
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from api.tests.functional.test_functional_api_fields import (
|
||||
APIFieldsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_appsettings
|
||||
class AppSettingsAPITestCases(
|
||||
APIFieldsInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def create_model(self, request, django_db_blocker,
|
||||
model, model_kwargs, api_request_permissions
|
||||
):
|
||||
|
||||
item = None
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = model.objects.get(
|
||||
owner_organization = None
|
||||
)
|
||||
|
||||
request.cls.item = item
|
||||
|
||||
yield item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def make_request(self, django_db_blocker,
|
||||
request,
|
||||
api_request_permissions,
|
||||
):
|
||||
|
||||
client = Client()
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
api_request_permissions['user']['view'].is_superuser = True
|
||||
api_request_permissions['user']['view'].save()
|
||||
|
||||
client.force_login( api_request_permissions['user']['view'] )
|
||||
response = client.get( self.item.get_url() )
|
||||
|
||||
request.cls.api_data = response.data
|
||||
|
||||
|
||||
|
||||
item_two = getattr(request.cls, 'item_two', None)
|
||||
|
||||
if item_two:
|
||||
|
||||
response_two = client.get( self.item_two.get_url() )
|
||||
|
||||
request.cls.api_data_two = response_two.data
|
||||
|
||||
else:
|
||||
|
||||
request.cls.api_data_two = {}
|
||||
|
||||
|
||||
yield
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_api_fields(self):
|
||||
|
||||
return {
|
||||
'_urls.notes': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'model_notes': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.id': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.display_name': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.url': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
# 'owner_organization': {
|
||||
# 'expected': dict
|
||||
# },
|
||||
# 'owner_organization.id': {
|
||||
# 'expected': int
|
||||
# },
|
||||
# 'owner_organization.display_name': {
|
||||
# 'expected': str
|
||||
# },
|
||||
# 'owner_organization.url': {
|
||||
# 'expected': Hyperlink
|
||||
# },
|
||||
'device_model_is_global': {
|
||||
'expected': bool
|
||||
},
|
||||
'device_type_is_global': {
|
||||
'expected': bool
|
||||
},
|
||||
'manufacturer_is_global': {
|
||||
'expected': bool
|
||||
},
|
||||
'software_is_global': {
|
||||
'expected': bool
|
||||
},
|
||||
'software_categories_is_global': {
|
||||
'expected': bool
|
||||
},
|
||||
'global_organization': {
|
||||
'expected': dict
|
||||
},
|
||||
'global_organization.id': {
|
||||
'expected': int
|
||||
},
|
||||
'global_organization.display_name': {
|
||||
'expected': str
|
||||
},
|
||||
'global_organization.url': {
|
||||
'expected': Hyperlink
|
||||
},
|
||||
'modified': {
|
||||
'expected': str
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class AppSettingsAPIInheritedCases(
|
||||
AppSettingsAPITestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsAPIPyTest(
|
||||
AppSettingsAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -3,22 +3,12 @@ import pytest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
from django import urls
|
||||
from django.test import TestCase
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_permissions_viewset import (
|
||||
APIPermissionChange,
|
||||
APIPermissionView
|
||||
)
|
||||
from api.tests.abstract.api_serializer_viewset import (
|
||||
SerializerChange,
|
||||
SerializerView,
|
||||
)
|
||||
from api.tests.abstract.test_metadata_functional import (
|
||||
MetadataAttributesFunctionalBase,
|
||||
MetadataAttributesFunctionalEndpoint
|
||||
@ -30,6 +20,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_appsettings
|
||||
class ViewSetBase:
|
||||
|
||||
model = AppSettings
|
||||
@ -193,17 +184,8 @@ class ViewSetBase:
|
||||
)
|
||||
|
||||
|
||||
class AppSettingsViewSet(
|
||||
ViewSetBase,
|
||||
SerializerChange,
|
||||
SerializerView,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctionalEndpoint,
|
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_appsettings
|
||||
class AppSettingsModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class AppSettingsModelInheritedCases(
|
||||
AppSettingsModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsModelPyTest(
|
||||
AppSettingsModelTestCases,
|
||||
):
|
||||
pass
|
25
app/settings/tests/functional/external_links/conftest.py
Normal file
25
app/settings/tests/functional/external_links/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_externallink):
|
||||
|
||||
yield model_externallink
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_externallink):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_externallink.copy()
|
||||
|
||||
yield kwargs_externallink.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_externallink):
|
||||
|
||||
yield serializer_externallink
|
@ -1,117 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
|
||||
from centurion.tests.abstract.mock_view import MockView, User
|
||||
|
||||
from settings.serializers.external_links import (
|
||||
ExternalLink,
|
||||
ExternalLinkModelSerializer
|
||||
)
|
||||
|
||||
|
||||
|
||||
class ExternalLinkValidationAPI(
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ExternalLink
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an org
|
||||
2. Create an item
|
||||
"""
|
||||
|
||||
organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.valid_data: dict = {
|
||||
'organization': self.organization.id,
|
||||
'name': 'a name',
|
||||
'template': 'http://example.com/{{ val }}'
|
||||
}
|
||||
|
||||
self.mock_view = MockView( user = self.user )
|
||||
|
||||
|
||||
|
||||
|
||||
def test_serializer_valid_data(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating an item with valid data that
|
||||
no errors occur
|
||||
"""
|
||||
|
||||
serializer = ExternalLinkModelSerializer(
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data = self.valid_data
|
||||
)
|
||||
|
||||
assert serializer.is_valid(raise_exception = True)
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_name(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
del data['name']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = ExternalLinkModelSerializer(
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_template(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no template is provided a validation error occurs
|
||||
"""
|
||||
|
||||
data = self.valid_data.copy()
|
||||
|
||||
del data['template']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = ExternalLinkModelSerializer(
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data = data
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['template'][0] == 'required'
|
@ -1,11 +1,7 @@
|
||||
import django
|
||||
import pytest
|
||||
import unittest
|
||||
import requests
|
||||
|
||||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import AnonymousUser, Permission
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.test import TestCase
|
||||
|
||||
@ -13,8 +9,6 @@ from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_permissions_viewset import APIPermissions
|
||||
from api.tests.abstract.api_serializer_viewset import SerializersTestCases
|
||||
from api.tests.abstract.test_metadata_functional import MetadataAttributesFunctional
|
||||
|
||||
from settings.models.external_link import ExternalLink
|
||||
@ -23,6 +17,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
class ViewSetBase:
|
||||
|
||||
model = ExternalLink
|
||||
@ -199,28 +194,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class ExternalLinkPermissionsAPI(ViewSetBase, APIPermissions, TestCase):
|
||||
|
||||
|
||||
def test_returned_data_from_user_and_global_organizations_only(self):
|
||||
"""Check items returned
|
||||
|
||||
This test case is a over-ride of a test case with the same name.
|
||||
This model is not a tenancy model making this test not-applicable.
|
||||
|
||||
Items returned from the query Must be from the users organization and
|
||||
global ONLY!
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ExternalLinkViewSet(ViewSetBase, SerializersTestCases, TestCase):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctional,
|
@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
from django.test import Client
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from api.tests.functional.test_functional_api_fields import (
|
||||
APIFieldsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
class ExternalLinkAPITestCases(
|
||||
APIFieldsInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_api_fields(self):
|
||||
|
||||
return {
|
||||
'name': {
|
||||
'expected': str
|
||||
},
|
||||
'button_text': {
|
||||
'expected': str
|
||||
},
|
||||
'template': {
|
||||
'expected': str
|
||||
},
|
||||
'colour': {
|
||||
'expected': str
|
||||
},
|
||||
'cluster': {
|
||||
'expected': bool
|
||||
},
|
||||
'devices': {
|
||||
'expected': bool
|
||||
},
|
||||
'service': {
|
||||
'expected': bool
|
||||
},
|
||||
'software': {
|
||||
'expected': bool
|
||||
},
|
||||
'modified': {
|
||||
'expected': str
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ExternalLinkAPIInheritedCases(
|
||||
ExternalLinkAPITestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkAPIPyTest(
|
||||
ExternalLinkAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
class ExternalLinkModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ExternalLinkModelInheritedCases(
|
||||
ExternalLinkModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkModelPyTest(
|
||||
ExternalLinkModelTestCases,
|
||||
):
|
||||
pass
|
25
app/settings/tests/functional/user_settings/conftest.py
Normal file
25
app/settings/tests/functional/user_settings/conftest.py
Normal file
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_usersettings):
|
||||
|
||||
yield model_usersettings
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_usersettings):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_usersettings.copy()
|
||||
|
||||
yield kwargs_usersettings.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_usersettings):
|
||||
|
||||
yield serializer_usersettings
|
@ -0,0 +1,107 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
from api.tests.functional.test_functional_api_fields import (
|
||||
APIFieldsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_usersettings
|
||||
class UserSettingsAPITestCases(
|
||||
APIFieldsInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def create_model(self, request, django_db_blocker,
|
||||
model, model_kwargs, api_request_permissions
|
||||
):
|
||||
|
||||
item = None
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item = model.objects.get(
|
||||
id = api_request_permissions['user']['view'].id
|
||||
)
|
||||
|
||||
request.cls.item = item
|
||||
|
||||
yield item
|
||||
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_api_fields(self):
|
||||
|
||||
return {
|
||||
'_urls.notes': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'model_notes': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.id': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.display_name': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'organization.url': {
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'user': {
|
||||
'expected': int
|
||||
},
|
||||
'user.id': { # Must not exist as the pk is the user ID
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'user.display_name': { # Must not exist as the pk is the user ID
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'user.url': { # Must not exist as the pk is the user ID
|
||||
'expected': models.NOT_PROVIDED
|
||||
},
|
||||
'browser_mode': { # Must not exist as the pk is the user ID
|
||||
'expected': int
|
||||
},
|
||||
# 'default_organization': { # Not yet required
|
||||
# 'expected': dict
|
||||
# },
|
||||
# 'default_organization.id': {
|
||||
# 'expected': int
|
||||
# },
|
||||
# 'default_organization.display_name': {
|
||||
# 'expected': str
|
||||
# },
|
||||
# 'default_organization.url': {
|
||||
# 'expected': Hyperlink
|
||||
# },
|
||||
'timezone': {
|
||||
'expected': str
|
||||
},
|
||||
'modified': {
|
||||
'expected': str
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class UserSettingsAPIInheritedCases(
|
||||
UserSettingsAPITestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsAPIPyTest(
|
||||
UserSettingsAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -5,20 +5,11 @@ from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
from django.test import TestCase
|
||||
# from django import urls
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
# from api.tests.abstract.api_permissions_viewset import (
|
||||
# APIPermissionChange,
|
||||
# APIPermissionView
|
||||
# )
|
||||
from api.tests.abstract.api_serializer_viewset import (
|
||||
SerializerChange,
|
||||
SerializerView,
|
||||
)
|
||||
from api.tests.abstract.test_metadata_functional import (
|
||||
MetadataAttributesFunctionalEndpoint,
|
||||
MetadataAttributesFunctionalBase,
|
||||
@ -32,7 +23,6 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
@pytest.mark.functional
|
||||
@pytest.mark.model_usersettings
|
||||
@pytest.mark.module_settings
|
||||
class ViewSetBase:
|
||||
|
||||
@ -198,17 +188,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class UserSettingsViewSet(
|
||||
ViewSetBase,
|
||||
SerializerChange,
|
||||
SerializerView,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_usersettings
|
||||
class UserSettingsMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctionalEndpoint,
|
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_usersettings
|
||||
class UserSettingsModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class UserSettingsModelInheritedCases(
|
||||
UserSettingsModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsModelPyTest(
|
||||
UserSettingsModelTestCases,
|
||||
):
|
||||
pass
|
@ -17,3 +17,9 @@ def model_kwargs(request, kwargs_appsettings):
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_appsettings):
|
||||
|
||||
yield serializer_appsettings
|
||||
|
@ -1,258 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_fields import APICommonFields
|
||||
|
||||
from settings.models.app_settings import AppSettings
|
||||
from settings.models.user_settings import UserSettings
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_appsettings
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsAPI(
|
||||
TestCase,
|
||||
APICommonFields
|
||||
):
|
||||
|
||||
model = AppSettings
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
self.item = AppSettings.objects.get( id = 1 )
|
||||
|
||||
self.item.global_organization = self.organization
|
||||
|
||||
self.item.save()
|
||||
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = self.organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password", is_superuser = True)
|
||||
|
||||
user_settings = UserSettings.objects.get(user = self.view_user)
|
||||
|
||||
user_settings.default_organization = self.organization
|
||||
|
||||
user_settings.save()
|
||||
|
||||
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
|
||||
self.url_view_kwargs = {'pk': self.item.id}
|
||||
|
||||
client = Client()
|
||||
url = reverse('v2:_api_appsettings-detail', kwargs=self.url_view_kwargs)
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
response = client.get(url)
|
||||
|
||||
self.api_data = response.data
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_device_model_is_global(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
device_model_is_global field must exist
|
||||
"""
|
||||
|
||||
assert 'device_model_is_global' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_device_model_is_global(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
device_model_is_global field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['device_model_is_global']) is bool
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_device_type_is_global(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
device_type_is_global field must exist
|
||||
"""
|
||||
|
||||
assert 'device_type_is_global' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_device_type_is_global(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
device_type_is_global field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['device_type_is_global']) is bool
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_manufacturer_is_global(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
manufacturer_is_global field must exist
|
||||
"""
|
||||
|
||||
assert 'manufacturer_is_global' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_manufacturer_is_global(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
manufacturer_is_global field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['manufacturer_is_global']) is bool
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_software_is_global(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
software_is_global field must exist
|
||||
"""
|
||||
|
||||
assert 'software_is_global' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_software_is_global(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
software_is_global field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['software_is_global']) is bool
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_software_categories_is_global(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
software_categories_is_global field must exist
|
||||
"""
|
||||
|
||||
assert 'software_categories_is_global' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_software_categories_is_global(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
software_categories_is_global field must be bool
|
||||
"""
|
||||
|
||||
assert type(self.api_data['software_categories_is_global']) is bool
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_global_organization(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
global_organization field must exist
|
||||
"""
|
||||
|
||||
assert 'global_organization' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_global_organization(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
global_organization field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['global_organization']) is dict
|
||||
|
||||
|
||||
def test_api_field_exists_global_organization_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
global_organization.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['global_organization']
|
||||
|
||||
|
||||
def test_api_field_type_global_organization_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
global_organization.id field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['global_organization']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_global_organization_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
global_organization.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['global_organization']
|
||||
|
||||
|
||||
def test_api_field_type_global_organization_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
global_organization.display_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['global_organization']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_global_organization_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
global_organization.url field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['global_organization']
|
||||
|
||||
|
||||
def test_api_field_type_global_organization_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
global_organization.url field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['global_organization']['url']) is Hyperlink
|
@ -0,0 +1,110 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from api.tests.unit.test_unit_serializer import (
|
||||
SerializerTestCases
|
||||
)
|
||||
|
||||
from centurion.tests.abstract.mock_view import MockView
|
||||
# from appsettings_management.serializers.app_settings import (
|
||||
# appse,
|
||||
# )
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_appsettings
|
||||
class AppSettingsSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def created_model(self, django_db_blocker, model, model_kwargs):
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
kwargs_many_to_many = {}
|
||||
|
||||
kwargs = {}
|
||||
|
||||
for key, value in model_kwargs.items():
|
||||
|
||||
field = model._meta.get_field(key)
|
||||
|
||||
if isinstance(field, models.ManyToManyField):
|
||||
|
||||
kwargs_many_to_many.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
else:
|
||||
|
||||
kwargs.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
|
||||
item = model.objects.create( **kwargs )
|
||||
|
||||
for key, value in kwargs_many_to_many.items():
|
||||
|
||||
field = getattr(item, key)
|
||||
|
||||
for entry in value:
|
||||
|
||||
field.add(entry)
|
||||
|
||||
yield item
|
||||
|
||||
item.delete()
|
||||
|
||||
|
||||
|
||||
# def test_serializer_validation_no_name(self,
|
||||
# kwargs_api_create, model, model_serializer, request_user
|
||||
# ):
|
||||
# """Serializer Validation Check
|
||||
|
||||
# Ensure that if creating and no name is provided a validation error occurs
|
||||
# """
|
||||
|
||||
# mock_view = MockView(
|
||||
# user = request_user,
|
||||
# model = model,
|
||||
# action = 'create',
|
||||
# )
|
||||
|
||||
# kwargs = kwargs_api_create.copy()
|
||||
# del kwargs['name']
|
||||
|
||||
# with pytest.raises(ValidationError) as err:
|
||||
|
||||
# serializer = model_serializer['model'](
|
||||
# context = {
|
||||
# 'request': mock_view.request,
|
||||
# 'view': mock_view,
|
||||
# },
|
||||
# data = kwargs,
|
||||
# )
|
||||
|
||||
# serializer.is_valid(raise_exception = True)
|
||||
|
||||
# assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
class AppSettingsSerializerInheritedCases(
|
||||
AppSettingsSerializerTestCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsSerializerPyTest(
|
||||
AppSettingsSerializerTestCases
|
||||
):
|
||||
pass
|
@ -1,48 +1,84 @@
|
||||
import pytest
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
from api.tests.unit.test_unit_common_viewset import (
|
||||
ModelRetrieveUpdateViewSetInheritedCases
|
||||
)
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelRetrieveUpdateViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.app_settings import ViewSet
|
||||
from settings.viewsets.app_settings import (
|
||||
AppSettings,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
@pytest.mark.model_appsettings
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsViewsetList(
|
||||
class ViewsetTestCases(
|
||||
ModelRetrieveUpdateViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_appsettings'
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.kwargs = {
|
||||
'pk': 1
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_log': {
|
||||
'type': type(None),
|
||||
},
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': []
|
||||
},
|
||||
'model': {
|
||||
'value': AppSettings
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': []
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'Centurion Settings'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-detail',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
class AppSettingsViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class AppSettingsViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
||||
|
@ -17,3 +17,9 @@ def model_kwargs(request, kwargs_externallink):
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_externallink):
|
||||
|
||||
yield serializer_externallink
|
||||
|
@ -1,151 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_fields import APITenancyObject
|
||||
|
||||
from settings.models.external_link import ExternalLink
|
||||
from settings.models.user_settings import UserSettings
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkAPI(
|
||||
TestCase,
|
||||
APITenancyObject
|
||||
):
|
||||
|
||||
model = ExternalLink
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = self.organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
user_settings = UserSettings.objects.get(user = self.view_user)
|
||||
|
||||
user_settings.default_organization = self.organization
|
||||
|
||||
user_settings.save()
|
||||
|
||||
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization=self.organization,
|
||||
name = 'state',
|
||||
button_text = 'text',
|
||||
model_notes = 'sakjdhjak',
|
||||
template = 'boo',
|
||||
colour = '#fff'
|
||||
)
|
||||
|
||||
self.url_view_kwargs = {'pk': self.item.id}
|
||||
|
||||
client = Client()
|
||||
url = reverse('v2:_api_externallink-detail', kwargs=self.url_view_kwargs)
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
response = client.get(url)
|
||||
|
||||
self.api_data = response.data
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_button_text(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
button_text field must exist
|
||||
"""
|
||||
|
||||
assert 'button_text' in self.api_data
|
||||
|
||||
|
||||
|
||||
def test_api_field_type_button_text(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
button_text field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['button_text']) is str
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_template(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
template field must exist
|
||||
"""
|
||||
|
||||
assert 'template' in self.api_data
|
||||
|
||||
|
||||
|
||||
def test_api_field_type_template(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
template field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['template']) is str
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_colour(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
colour field must exist
|
||||
"""
|
||||
|
||||
assert 'colour' in self.api_data
|
||||
|
||||
|
||||
|
||||
def test_api_field_type_colour(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
colour field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['colour']) is str
|
@ -0,0 +1,140 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
from rest_framework.exceptions import ValidationError
|
||||
|
||||
from api.tests.unit.test_unit_serializer import (
|
||||
SerializerTestCases
|
||||
)
|
||||
|
||||
from centurion.tests.abstract.mock_view import MockView
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
class ExternalLinkSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def created_model(self, django_db_blocker, model, model_kwargs):
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
kwargs_many_to_many = {}
|
||||
|
||||
kwargs = {}
|
||||
|
||||
for key, value in model_kwargs.items():
|
||||
|
||||
field = model._meta.get_field(key)
|
||||
|
||||
if isinstance(field, models.ManyToManyField):
|
||||
|
||||
kwargs_many_to_many.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
else:
|
||||
|
||||
kwargs.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
|
||||
item = model.objects.create( **kwargs )
|
||||
|
||||
for key, value in kwargs_many_to_many.items():
|
||||
|
||||
field = getattr(item, key)
|
||||
|
||||
for entry in value:
|
||||
|
||||
field.add(entry)
|
||||
|
||||
yield item
|
||||
|
||||
item.delete()
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_name(self,
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
kwargs = kwargs_api_create.copy()
|
||||
del kwargs['name']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_template(self,
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no template is provided a validation error occurs
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
kwargs = kwargs_api_create.copy()
|
||||
del kwargs['template']
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['template'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
class ExternalLinkSerializerInheritedCases(
|
||||
ExternalLinkSerializerTestCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkSerializerPyTest(
|
||||
ExternalLinkSerializerTestCases
|
||||
):
|
||||
pass
|
@ -1,45 +1,89 @@
|
||||
import pytest
|
||||
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.external_link import ViewSet
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
@pytest.mark.model_externallink
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinksViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_externallink'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
from api.tests.unit.test_unit_common_viewset import (
|
||||
ModelRetrieveUpdateViewSetInheritedCases
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
from settings.viewsets.external_link import (
|
||||
ExternalLink,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
||||
|
||||
|
||||
@pytest.mark.model_externallink
|
||||
class ViewsetTestCases(
|
||||
ModelRetrieveUpdateViewSetInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_log': {
|
||||
'type': type(None),
|
||||
},
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': [
|
||||
'cluster',
|
||||
'devices',
|
||||
'service',
|
||||
'software'
|
||||
]
|
||||
},
|
||||
'model': {
|
||||
'value': ExternalLink
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': []
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'External Link tags'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ExternalLinkViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class ExternalLinkViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
||||
|
@ -17,3 +17,9 @@ def model_kwargs(request, kwargs_usersettings):
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_usersettings):
|
||||
|
||||
yield serializer_usersettings
|
||||
|
@ -0,0 +1,108 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
# from rest_framework.exceptions import ValidationError
|
||||
|
||||
from api.tests.unit.test_unit_serializer import (
|
||||
SerializerTestCases
|
||||
)
|
||||
|
||||
from centurion.tests.abstract.mock_view import MockView
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_usersettings
|
||||
class UserSettingsSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def created_model(self, django_db_blocker, model, model_kwargs):
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
kwargs_many_to_many = {}
|
||||
|
||||
kwargs = {}
|
||||
|
||||
for key, value in model_kwargs.items():
|
||||
|
||||
field = model._meta.get_field(key)
|
||||
|
||||
if isinstance(field, models.ManyToManyField):
|
||||
|
||||
kwargs_many_to_many.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
else:
|
||||
|
||||
kwargs.update({
|
||||
key: value
|
||||
})
|
||||
|
||||
|
||||
item = model.objects.create( **kwargs )
|
||||
|
||||
for key, value in kwargs_many_to_many.items():
|
||||
|
||||
field = getattr(item, key)
|
||||
|
||||
for entry in value:
|
||||
|
||||
field.add(entry)
|
||||
|
||||
yield item
|
||||
|
||||
item.delete()
|
||||
|
||||
|
||||
@pytest.mark.regression
|
||||
def test_serializer_create_calls_model_full_clean(self, created_model,
|
||||
kwargs_api_create, mocker, model, model_serializer, request_user
|
||||
):
|
||||
""" Serializer Check
|
||||
|
||||
Confirm that using valid data the object validates without exceptions.
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
created_model,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs_api_create,
|
||||
partial = True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
full_clean = mocker.spy(model, 'full_clean')
|
||||
|
||||
serializer.save()
|
||||
|
||||
full_clean.assert_called_once()
|
||||
|
||||
|
||||
|
||||
class UserSettingsSerializerInheritedCases(
|
||||
UserSettingsSerializerTestCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsSerializerPyTest(
|
||||
UserSettingsSerializerTestCases
|
||||
):
|
||||
pass
|
@ -1,50 +1,84 @@
|
||||
import pytest
|
||||
|
||||
from django.test import Client, TestCase
|
||||
from api.tests.unit.test_unit_common_viewset import (
|
||||
ModelRetrieveUpdateViewSetInheritedCases
|
||||
)
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelRetrieveUpdateViewSetInheritedCases
|
||||
|
||||
from settings.viewsets.user_settings import ViewSet
|
||||
from settings.viewsets.user_settings import (
|
||||
UserSettings,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
@pytest.mark.model_usersettings
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsViewsetList(
|
||||
class ViewsetTestCases(
|
||||
ModelRetrieveUpdateViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_usersettings'
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
self.kwargs = {
|
||||
'pk': self.view_user.id
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_log': {
|
||||
'type': type(None),
|
||||
},
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': []
|
||||
},
|
||||
'model': {
|
||||
'value': UserSettings
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': []
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'Your Settings'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-detail',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
class UserSettingsViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
||||
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
||||
|
@ -1,183 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
from access.models.team import Team
|
||||
from access.models.team_user import TeamUsers
|
||||
|
||||
from api.tests.abstract.api_fields import APICommonFields
|
||||
|
||||
from settings.models.user_settings import UserSettings
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_usersettings
|
||||
@pytest.mark.module_settings
|
||||
class UserSettingsAPI(
|
||||
TestCase,
|
||||
APICommonFields
|
||||
):
|
||||
|
||||
model = UserSettings
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
self.organization = Organization.objects.create(name='test_org')
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
app_label = self.model._meta.app_label,
|
||||
model = self.model._meta.model_name,
|
||||
)
|
||||
)
|
||||
|
||||
view_team = Team.objects.create(
|
||||
team_name = 'view_team',
|
||||
organization = self.organization,
|
||||
)
|
||||
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
self.view_user = User.objects.create_user(username="test_user_view", password="password")
|
||||
|
||||
|
||||
|
||||
self.item = self.model.objects.get( id = self.view_user.id )
|
||||
|
||||
self.item.default_organization = self.organization
|
||||
|
||||
self.item.save()
|
||||
|
||||
|
||||
|
||||
user_settings = UserSettings.objects.get(user = self.view_user)
|
||||
|
||||
user_settings.default_organization = self.organization
|
||||
|
||||
user_settings.save()
|
||||
|
||||
|
||||
teamuser = TeamUsers.objects.create(
|
||||
team = view_team,
|
||||
user = self.view_user
|
||||
)
|
||||
|
||||
|
||||
self.url_view_kwargs = {'pk': self.item.id}
|
||||
|
||||
client = Client()
|
||||
url = reverse('v2:_api_usersettings-detail', kwargs=self.url_view_kwargs)
|
||||
|
||||
|
||||
client.force_login(self.view_user)
|
||||
response = client.get(url)
|
||||
|
||||
self.api_data = response.data
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_default_organization(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
default_organization field must exist
|
||||
"""
|
||||
|
||||
assert 'default_organization' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_default_organization(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
default_organization field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['default_organization']) is dict
|
||||
|
||||
|
||||
def test_api_field_exists_default_organization_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
default_organization.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['default_organization']
|
||||
|
||||
|
||||
def test_api_field_type_default_organization_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
default_organization.id field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['default_organization']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_default_organization_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
default_organization.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['default_organization']
|
||||
|
||||
|
||||
def test_api_field_type_default_organization_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
default_organization.display_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['default_organization']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_default_organization_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
default_organization.url field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['default_organization']
|
||||
|
||||
|
||||
def test_api_field_type_default_organization_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
default_organization.url field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['default_organization']['url']) is Hyperlink
|
||||
|
||||
|
||||
def test_api_field_exists_browser_mode(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
browser_mode field must exist
|
||||
"""
|
||||
|
||||
assert 'browser_mode' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_browser_mode(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
browser_mode field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['browser_mode']) is int
|
3
app/tests/fixtures/__init__.py
vendored
3
app/tests/fixtures/__init__.py
vendored
@ -16,6 +16,7 @@ from .mixin_centurion import (
|
||||
from .model_appsettings import (
|
||||
kwargs_appsettings,
|
||||
model_appsettings,
|
||||
serializer_appsettings,
|
||||
)
|
||||
|
||||
from .model_assetbase import (
|
||||
@ -144,6 +145,7 @@ from .model_entity import (
|
||||
from .model_externallink import (
|
||||
kwargs_externallink,
|
||||
model_externallink,
|
||||
serializer_externallink,
|
||||
)
|
||||
|
||||
from .model_featureflag import (
|
||||
@ -360,4 +362,5 @@ from .model_user import (
|
||||
from .model_usersettings import (
|
||||
kwargs_usersettings,
|
||||
model_usersettings,
|
||||
serializer_usersettings,
|
||||
)
|
||||
|
15
app/tests/fixtures/model_appsettings.py
vendored
15
app/tests/fixtures/model_appsettings.py
vendored
@ -2,6 +2,11 @@ import datetime
|
||||
import pytest
|
||||
|
||||
from settings.models.app_settings import AppSettings
|
||||
from settings.serializers.app_settings import (
|
||||
AppSettingsBaseSerializer,
|
||||
AppSettingsModelSerializer,
|
||||
AppSettingsViewSerializer
|
||||
)
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_appsettings():
|
||||
@ -31,3 +36,13 @@ def kwargs_appsettings( django_db_blocker, model_user ):
|
||||
|
||||
user.delete()
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def serializer_appsettings():
|
||||
|
||||
yield {
|
||||
'base': AppSettingsBaseSerializer,
|
||||
'model': AppSettingsModelSerializer,
|
||||
'view': AppSettingsViewSerializer
|
||||
}
|
||||
|
||||
|
20
app/tests/fixtures/model_externallink.py
vendored
20
app/tests/fixtures/model_externallink.py
vendored
@ -2,6 +2,13 @@ import datetime
|
||||
import pytest
|
||||
|
||||
from settings.models.external_link import ExternalLink
|
||||
from settings.serializers.external_links import (
|
||||
ExternalLinkBaseSerializer,
|
||||
ExternalLinkModelSerializer,
|
||||
ExternalLinkViewSerializer,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_externallink():
|
||||
@ -20,7 +27,18 @@ def kwargs_externallink( kwargs_centurionmodel ):
|
||||
**kwargs_centurionmodel.copy(),
|
||||
'name': 'el' + random_str,
|
||||
'button_text': 'bt' + random_str,
|
||||
'template': 'boo'
|
||||
'template': 'boo',
|
||||
'colour': '#00FF00',
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def serializer_externallink():
|
||||
|
||||
yield {
|
||||
'base': ExternalLinkBaseSerializer,
|
||||
'model': ExternalLinkModelSerializer,
|
||||
'view': ExternalLinkViewSerializer
|
||||
}
|
||||
|
25
app/tests/fixtures/model_usersettings.py
vendored
25
app/tests/fixtures/model_usersettings.py
vendored
@ -2,6 +2,13 @@ import datetime
|
||||
import pytest
|
||||
|
||||
from settings.models.user_settings import UserSettings
|
||||
from settings.serializers.user_settings import (
|
||||
UserSettingsBaseSerializer,
|
||||
UserSettingsModelSerializer,
|
||||
UserSettingsViewSerializer,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_usersettings():
|
||||
@ -9,6 +16,7 @@ def model_usersettings():
|
||||
yield UserSettings
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_usersettings( django_db_blocker, model_user ):
|
||||
|
||||
@ -23,12 +31,6 @@ def kwargs_usersettings( django_db_blocker, model_user ):
|
||||
password = 'password'
|
||||
)
|
||||
|
||||
# user_settings = UserSettings.objects.get(
|
||||
# user = user
|
||||
# )
|
||||
|
||||
# user_settings.delete() # Remove default created
|
||||
|
||||
|
||||
kwargs = {
|
||||
'user': user,
|
||||
@ -39,3 +41,14 @@ def kwargs_usersettings( django_db_blocker, model_user ):
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
user.delete()
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def serializer_usersettings():
|
||||
|
||||
yield {
|
||||
'base': UserSettingsBaseSerializer,
|
||||
'model': UserSettingsModelSerializer,
|
||||
'view': UserSettingsViewSerializer
|
||||
}
|
||||
|
Reference in New Issue
Block a user