Merge pull request #908 from nofusscomputing/config_management-refactor-tests
This commit is contained in:
@ -377,6 +377,7 @@ class CommonViewSetTestCases(
|
||||
)
|
||||
|
||||
view_set.request = request
|
||||
view_set.kwargs = {}
|
||||
|
||||
yield view_set
|
||||
|
||||
|
@ -61,7 +61,8 @@ class KnowledgeBaseSerializerTestCases(
|
||||
|
||||
|
||||
def test_serializer_validation_no_title(self,
|
||||
kwargs_api_create, model, model_serializer, request_user):
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no title is provided a validation error occurs
|
||||
|
@ -1,126 +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 config_management.serializers.config_group import ConfigGroups, ConfigGroupModelSerializer
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsValidationAPI(
|
||||
TestCase,
|
||||
):
|
||||
|
||||
model = ConfigGroups
|
||||
|
||||
@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.mock_view = MockView( user = self.user )
|
||||
|
||||
self.organization = organization
|
||||
|
||||
self.item_no_parent = self.model.objects.create(
|
||||
organization=organization,
|
||||
name = 'random title',
|
||||
config = { 'config_key': 'a value' }
|
||||
)
|
||||
|
||||
self.item_has_parent = self.model.objects.create(
|
||||
organization=organization,
|
||||
name = 'random title two',
|
||||
parent = self.item_no_parent
|
||||
)
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_no_name(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if creating and no name is provided a validation error occurs
|
||||
"""
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = ConfigGroupModelSerializer(
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data={
|
||||
"organization": self.organization.id,
|
||||
})
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['name'][0] == 'required'
|
||||
|
||||
|
||||
|
||||
def test_serializer_validation_update_existing_parnet_not_self(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if an existing item is assigned itself as it's parent group
|
||||
it raises a validation error
|
||||
"""
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = ConfigGroupModelSerializer(
|
||||
self.item_has_parent,
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data={
|
||||
"parent": self.item_has_parent.id
|
||||
},
|
||||
partial=True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['parent'][0] == 'self_not_parent'
|
||||
|
||||
|
||||
def test_serializer_validation_update_existing_invalid_config_key(self):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if an existing item has it's config updated with an invalid config key
|
||||
a validation exception is raised.
|
||||
"""
|
||||
|
||||
invalid_config = self.item_no_parent.config.copy()
|
||||
invalid_config.update({ 'software': 'is invalid' })
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = ConfigGroupModelSerializer(
|
||||
self.item_no_parent,
|
||||
context = {
|
||||
'request': self.mock_view.request,
|
||||
'view': self.mock_view,
|
||||
},
|
||||
data={
|
||||
"config": invalid_config
|
||||
},
|
||||
partial=True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['config'][0] == 'invalid'
|
@ -0,0 +1,25 @@
|
||||
import pytest
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(model_configgroups):
|
||||
|
||||
yield model_configgroups
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def model_kwargs(request, kwargs_configgroups):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_configgroups.copy()
|
||||
|
||||
yield kwargs_configgroups.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_configgroups):
|
||||
|
||||
yield serializer_configgroups
|
@ -0,0 +1,154 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
from rest_framework.relations import Hyperlink
|
||||
|
||||
from api.tests.functional.test_functional_api_fields import (
|
||||
APIFieldsInheritedCases,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroups
|
||||
class ConfigGroupsAPITestCases(
|
||||
APIFieldsInheritedCases,
|
||||
):
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def second_model(self, request, django_db_blocker,
|
||||
model, model_kwargs, model_device, kwargs_device
|
||||
):
|
||||
|
||||
item = None
|
||||
|
||||
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
|
||||
})
|
||||
|
||||
device = model_device.objects.create( **kwargs_device )
|
||||
|
||||
kwargs_many_to_many.update({
|
||||
'hosts': [ device ]
|
||||
})
|
||||
|
||||
kwargs.update({
|
||||
'parent': request.cls.item
|
||||
})
|
||||
|
||||
|
||||
item_two = model.objects.create(
|
||||
**kwargs
|
||||
)
|
||||
|
||||
|
||||
for key, value in kwargs_many_to_many.items():
|
||||
|
||||
field = getattr(item_two, key)
|
||||
|
||||
for entry in value:
|
||||
|
||||
field.add(entry)
|
||||
|
||||
|
||||
request.cls.item_two = item_two
|
||||
|
||||
yield item_two
|
||||
|
||||
with django_db_blocker.unblock():
|
||||
|
||||
item_two.delete()
|
||||
|
||||
device.delete()
|
||||
|
||||
del request.cls.item_two
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class', autouse = True)
|
||||
def class_setup(self,
|
||||
create_model,
|
||||
second_model,
|
||||
make_request,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
@property
|
||||
def parameterized_api_fields(self):
|
||||
|
||||
return {
|
||||
'parent': {
|
||||
'expected': dict
|
||||
},
|
||||
'parent.id': {
|
||||
'expected': int
|
||||
},
|
||||
'parent.display_name': {
|
||||
'expected': str
|
||||
},
|
||||
'parent.url': {
|
||||
'expected': str
|
||||
},
|
||||
'name': {
|
||||
'expected': str
|
||||
},
|
||||
'config': {
|
||||
'expected': dict
|
||||
},
|
||||
'config.key': {
|
||||
'expected': str
|
||||
},
|
||||
'config.existing': {
|
||||
'expected': str
|
||||
},
|
||||
|
||||
'hosts': {
|
||||
'expected': list
|
||||
},
|
||||
'hosts.0.id': {
|
||||
'expected': int
|
||||
},
|
||||
'hosts.0.display_name': {
|
||||
'expected': str
|
||||
},
|
||||
'hosts.0.url': {
|
||||
'expected': str
|
||||
},
|
||||
'modified': {
|
||||
'expected': str
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsAPIInheritedCases(
|
||||
ConfigGroupsAPITestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsAPIPyTest(
|
||||
ConfigGroupsAPITestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -1,11 +1,6 @@
|
||||
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 +8,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, MetaDataNavigationEntriesFunctional
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
@ -25,13 +18,13 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroups
|
||||
class ViewSetBase:
|
||||
|
||||
model = ConfigGroups
|
||||
|
||||
app_namespace = 'v2'
|
||||
|
||||
|
||||
url_name = '_api_configgroups'
|
||||
|
||||
change_data = {'name': 'device'}
|
||||
@ -57,10 +50,6 @@ class ViewSetBase:
|
||||
|
||||
self.different_organization = different_organization
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
self.global_organization = Organization.objects.create(
|
||||
name = 'test_global_organization'
|
||||
)
|
||||
@ -79,9 +68,6 @@ class ViewSetBase:
|
||||
app_settings.save()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
view_permissions = Permission.objects.get(
|
||||
codename = 'view_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
@ -98,7 +84,6 @@ class ViewSetBase:
|
||||
view_team.permissions.set([view_permissions])
|
||||
|
||||
|
||||
|
||||
add_permissions = Permission.objects.get(
|
||||
codename = 'add_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
@ -115,7 +100,6 @@ class ViewSetBase:
|
||||
add_team.permissions.set([add_permissions])
|
||||
|
||||
|
||||
|
||||
change_permissions = Permission.objects.get(
|
||||
codename = 'change_' + self.model._meta.model_name,
|
||||
content_type = ContentType.objects.get(
|
||||
@ -219,26 +203,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsPermissionsAPI(
|
||||
ViewSetBase,
|
||||
APIPermissions,
|
||||
TestCase
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsViewSet(
|
||||
ViewSetBase,
|
||||
SerializersTestCases,
|
||||
TestCase
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctional,
|
@ -0,0 +1,28 @@
|
||||
import pytest
|
||||
|
||||
from core.tests.functional.centurion_abstract.test_functional_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroups
|
||||
class ConfigGroupsModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsModelInheritedCases(
|
||||
ConfigGroupsModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsModelPyTest(
|
||||
ConfigGroupsModelTestCases,
|
||||
):
|
||||
pass
|
@ -13,6 +13,8 @@ from itam.models.software import Software, SoftwareVersion
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroupsoftware
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupSoftwareValidationAPI(
|
||||
TestCase,
|
||||
):
|
@ -1,11 +1,7 @@
|
||||
import django
|
||||
import pytest
|
||||
import unittest
|
||||
import requests
|
||||
import django
|
||||
|
||||
|
||||
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 config_management.models.groups import ConfigGroups, ConfigGroupSoftware, Software, SoftwareVersion
|
||||
@ -23,6 +17,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroupsoftware
|
||||
class ViewSetBase:
|
||||
|
||||
model = ConfigGroupSoftware
|
||||
@ -236,37 +231,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class ConfigGroupSoftwarePermissionsAPI(
|
||||
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 ConfigGroupSoftwareViewSet(
|
||||
ViewSetBase,
|
||||
SerializersTestCases,
|
||||
TestCase
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupSoftwareMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctional,
|
@ -1,103 +0,0 @@
|
||||
|
||||
from django.shortcuts import reverse
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from core.tests.abstract.test_item_ticket_api_v2 import ItemTicketAPI
|
||||
|
||||
from core.models.ticket.ticket_linked_items import TicketLinkedItem
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsTicketAPI(
|
||||
ItemTicketAPI,
|
||||
TestCase,
|
||||
):
|
||||
"""Test Cases for Item Tickets
|
||||
|
||||
Args:
|
||||
APITenancyObject (class): Base class for ALL field checks
|
||||
"""
|
||||
|
||||
item_type = TicketLinkedItem.Modules.CONFIG_GROUP
|
||||
|
||||
item_class = 'config_group'
|
||||
|
||||
item_model = ConfigGroups
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. Create an organization for user and item
|
||||
2. Create an item
|
||||
|
||||
"""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
self.linked_item = self.item_model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'dev'
|
||||
)
|
||||
|
||||
|
||||
|
||||
self.item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
ticket = self.ticket,
|
||||
|
||||
# Item attributes
|
||||
|
||||
item = self.linked_item.id,
|
||||
item_type = self.item_type,
|
||||
)
|
||||
|
||||
|
||||
|
||||
self.url_view_kwargs = {
|
||||
'item_class': self.item_class,
|
||||
'item_id': self.item.id,
|
||||
'pk': self.item.id,
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
url = reverse('v2:_api_v2_item_tickets-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_value_item_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
item.id field must exist
|
||||
"""
|
||||
|
||||
assert self.api_data['item']['id'] == self.linked_item.id
|
||||
|
||||
|
||||
|
||||
def test_api_field_value_item_type(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
item_type field must be int
|
||||
"""
|
||||
|
||||
assert self.api_data['item_type'] == self.item_type
|
||||
|
||||
def test_api_field_type_item_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
item.url field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['item']['url']) is str
|
@ -1,196 +0,0 @@
|
||||
import django
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
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 config_management.models.groups import ConfigGroups
|
||||
|
||||
User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsAPI(
|
||||
TestCase,
|
||||
APITenancyObject
|
||||
):
|
||||
|
||||
model = ConfigGroups
|
||||
|
||||
@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 = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'one',
|
||||
config = dict({"key": "one", "existing": "dont_over_write"})
|
||||
)
|
||||
|
||||
self.second_item = self.model.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'one_two',
|
||||
model_notes = 'stuff',
|
||||
config = dict({"key": "two"}),
|
||||
parent = self.item
|
||||
)
|
||||
|
||||
self.url_view_kwargs = {'pk': self.second_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 = self.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
|
||||
)
|
||||
|
||||
client = Client()
|
||||
url = reverse('v2:_api_configgroups-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_config(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
config field must exist
|
||||
"""
|
||||
|
||||
assert 'config' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_config(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
config field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['config']) is dict
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_parent(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
parent field must exist
|
||||
"""
|
||||
|
||||
assert 'parent' in self.api_data
|
||||
|
||||
|
||||
def test_api_field_type_parent(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
parent field must be dict
|
||||
"""
|
||||
|
||||
assert type(self.api_data['parent']) is dict
|
||||
|
||||
|
||||
def test_api_field_exists_parent_id(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
parent.id field must exist
|
||||
"""
|
||||
|
||||
assert 'id' in self.api_data['parent']
|
||||
|
||||
|
||||
def test_api_field_type_parent_id(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
parent.id field must be int
|
||||
"""
|
||||
|
||||
assert type(self.api_data['parent']['id']) is int
|
||||
|
||||
|
||||
def test_api_field_exists_parent_display_name(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
parent.display_name field must exist
|
||||
"""
|
||||
|
||||
assert 'display_name' in self.api_data['parent']
|
||||
|
||||
|
||||
def test_api_field_type_parent_display_name(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
parent.display_name field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['parent']['display_name']) is str
|
||||
|
||||
|
||||
def test_api_field_exists_parent_url(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
parent.url field must exist
|
||||
"""
|
||||
|
||||
assert 'url' in self.api_data['parent']
|
||||
|
||||
|
||||
def test_api_field_type_parent_url(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
parent.url field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['parent']['url']) is str
|
||||
|
||||
|
||||
|
||||
def test_api_field_exists_urls_tickets(self):
|
||||
""" Test for existance of API Field
|
||||
|
||||
_urls.tickets field must exist
|
||||
"""
|
||||
|
||||
assert 'tickets' in self.api_data['_urls']
|
||||
|
||||
|
||||
def test_api_field_type_urls_tickets(self):
|
||||
""" Test for type for API Field
|
||||
|
||||
_urls.tickets field must be str
|
||||
"""
|
||||
|
||||
assert type(self.api_data['_urls']['tickets']) is str
|
@ -17,3 +17,9 @@ def model_kwargs(request, kwargs_configgroups):
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_serializer(serializer_configgroups):
|
||||
|
||||
yield serializer_configgroups
|
||||
|
@ -2,42 +2,71 @@ import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
|
||||
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
# class Old:
|
||||
|
||||
# kwargs_item_create = {
|
||||
# 'name': 'one',
|
||||
# 'config': dict({"key": "one", "existing": "dont_over_write"})
|
||||
# }
|
||||
|
||||
# model = ConfigGroups
|
||||
|
||||
# @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')
|
||||
|
||||
# super().setUpTestData()
|
||||
@pytest.mark.model_configgroups
|
||||
class ConfigGroupModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
|
||||
|
||||
# self.second_item = self.model.objects.create(
|
||||
# organization = self.organization,
|
||||
# name = 'one_two',
|
||||
# config = dict({"key": "two"}),
|
||||
# parent = self.item
|
||||
# )
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'model_tag': {
|
||||
'type': str,
|
||||
'value': 'config_group'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_model_fields(self):
|
||||
|
||||
return {
|
||||
'parent': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ForeignKey,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'name': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.CharField,
|
||||
'max_length': 50,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'config': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.JSONField,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'hosts': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ManyToManyField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'modified': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.DateTimeField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
# def test_config_groups_count_child_groups(self):
|
||||
# """ Test function count_children """
|
||||
@ -86,67 +115,6 @@ from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model impor
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroups
|
||||
class ConfigGroupModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'model_tag': {
|
||||
'type': str,
|
||||
'value': 'config_group'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_model_fields(self):
|
||||
|
||||
return {
|
||||
'parent': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ForeignKey,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'name': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.CharField,
|
||||
'max_length': 50,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'config': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.JSONField,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'hosts': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ManyToManyField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
'modified': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.DateTimeField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ConfigGroupModelInheritedCases(
|
||||
ConfigGroupModelTestCases,
|
||||
):
|
||||
|
@ -0,0 +1,179 @@
|
||||
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_configgroups
|
||||
class ConfigGroupsSerializerTestCases(
|
||||
SerializerTestCases
|
||||
):
|
||||
pass
|
||||
|
||||
@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_update_existing_parnet_not_self(self,
|
||||
created_model,
|
||||
kwargs_api_create, model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if an existing item is assigned itself as it's parent group
|
||||
it raises a validation error
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
kwargs = kwargs_api_create.copy()
|
||||
kwargs['parent'] = created_model.id
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
created_model,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data = kwargs,
|
||||
partial=True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['parent'][0] == 'self_not_parent'
|
||||
|
||||
|
||||
def test_serializer_validation_update_existing_invalid_config_key(self,
|
||||
created_model,
|
||||
model, model_serializer, request_user
|
||||
):
|
||||
"""Serializer Validation Check
|
||||
|
||||
Ensure that if an existing item has it's config updated with an invalid config key
|
||||
a validation exception is raised.
|
||||
"""
|
||||
|
||||
mock_view = MockView(
|
||||
user = request_user,
|
||||
model = model,
|
||||
action = 'create',
|
||||
)
|
||||
|
||||
with pytest.raises(ValidationError) as err:
|
||||
|
||||
serializer = model_serializer['model'](
|
||||
created_model,
|
||||
context = {
|
||||
'request': mock_view.request,
|
||||
'view': mock_view,
|
||||
},
|
||||
data={
|
||||
"config": {'software': 'is invalid'}
|
||||
},
|
||||
partial=True,
|
||||
)
|
||||
|
||||
serializer.is_valid(raise_exception = True)
|
||||
|
||||
assert err.value.get_codes()['config'][0] == 'invalid'
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsSerializerInheritedCases(
|
||||
ConfigGroupsSerializerTestCases
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsSerializerPyTest(
|
||||
ConfigGroupsSerializerTestCases
|
||||
):
|
||||
pass
|
@ -0,0 +1,99 @@
|
||||
import pytest
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from config_management.viewsets.config_group import (
|
||||
ConfigGroups,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroups
|
||||
class ViewsetTestCases(
|
||||
ModelViewSetInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': [
|
||||
'organization',
|
||||
'parent'
|
||||
]
|
||||
},
|
||||
'model': {
|
||||
'value': ConfigGroups
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': [
|
||||
'name',
|
||||
'config'
|
||||
]
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'Configuration Groups'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def test_view_func_get_queryset_cache_result_used(self, mocker, viewset, viewset_mock_request):
|
||||
|
||||
qs = mocker.spy(viewset_mock_request.model, 'objects')
|
||||
|
||||
viewset_mock_request.get_queryset() # Initial QuerySet fetch/filter and cache
|
||||
|
||||
assert len(qs.method_calls) == 1 # one call to .all()
|
||||
assert len(qs.mock_calls) == 3 # calls = .all(), all().filter()
|
||||
|
||||
viewset_mock_request.get_queryset() # Use Cached results, dont re-fetch QuerySet
|
||||
|
||||
assert len(qs.method_calls) == 1
|
||||
assert len(qs.mock_calls) == 3
|
||||
|
||||
|
||||
class KnowledgeBaseViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class KnowledgeBaseViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -1,42 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from config_management.viewsets.config_group import ViewSet
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
class ConfigGroupsViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_configgroups'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
@ -20,6 +20,8 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroupsoftware
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsAPI(
|
||||
TestCase,
|
||||
APITenancyObject
|
@ -72,6 +72,9 @@ class ConfigGroupSoftwareModelTestCases(
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'_notes_enabled': {
|
||||
'value': False,
|
||||
},
|
||||
'model_tag': {
|
||||
'type': models.NOT_PROVIDED,
|
||||
'value': models.NOT_PROVIDED,
|
||||
|
@ -0,0 +1,83 @@
|
||||
import pytest
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
|
||||
from config_management.viewsets.config_group_software import (
|
||||
ConfigGroupSoftware,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_configgroupsoftware
|
||||
class ViewsetTestCases(
|
||||
ModelViewSetInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': [
|
||||
'organization',
|
||||
'software'
|
||||
]
|
||||
},
|
||||
'model': {
|
||||
'value': ConfigGroupSoftware
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': []
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'Software for a config group'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ConfigGroupsViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_config_management
|
||||
class ConfigGroupsViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -1,52 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
from config_management.viewsets.config_group_software import ViewSet
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
class ConfigGroupsSoftwareViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_configgroupsoftware'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
cg = ConfigGroups.objects.create(
|
||||
organization = self.organization,
|
||||
name = 'cg'
|
||||
)
|
||||
|
||||
self.kwargs = {
|
||||
'config_group_id': cg.id
|
||||
}
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
@ -74,7 +74,7 @@ class ViewSet( ModelViewSet ):
|
||||
|
||||
model = ConfigGroups
|
||||
|
||||
view_description = 'Information Management Knowledge Base Article(s)'
|
||||
view_description = 'Configuration Groups'
|
||||
|
||||
|
||||
def get_queryset(self):
|
||||
@ -94,7 +94,7 @@ class ViewSet( ModelViewSet ):
|
||||
else:
|
||||
|
||||
self.queryset = super().get_queryset().filter( parent = None )
|
||||
|
||||
|
||||
return self.queryset
|
||||
|
||||
|
||||
@ -105,12 +105,13 @@ class ViewSet( ModelViewSet ):
|
||||
or self.action == 'retrieve'
|
||||
):
|
||||
|
||||
self.serializer_class = globals()[str( self.model._meta.verbose_name).replace(' ' , '') + 'ViewSerializer']
|
||||
self.serializer_class = globals()[str(
|
||||
self.model._meta.verbose_name).replace(' ' , '') + 'ViewSerializer']
|
||||
|
||||
else:
|
||||
|
||||
self.serializer_class = globals()[str( self.model._meta.verbose_name).replace(' ' , '') + 'ModelSerializer']
|
||||
self.serializer_class = globals()[str(
|
||||
self.model._meta.verbose_name).replace(' ' , '') + 'ModelSerializer']
|
||||
|
||||
|
||||
return self.serializer_class
|
||||
|
||||
|
@ -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 core.models.manufacturer import Manufacturer
|
||||
@ -26,6 +20,7 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_manufacturer
|
||||
class ViewSetBase:
|
||||
|
||||
model = Manufacturer
|
||||
@ -220,26 +215,7 @@ class ViewSetBase:
|
||||
|
||||
|
||||
|
||||
class ManufacturerPermissionsAPI(
|
||||
ViewSetBase,
|
||||
APIPermissions,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ManufacturerViewSet(
|
||||
ViewSetBase,
|
||||
SerializersTestCases,
|
||||
TestCase
|
||||
):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class ManufacturerMetadata(
|
||||
ViewSetBase,
|
||||
MetadataAttributesFunctional,
|
@ -10,6 +10,8 @@ from core.serializers.manufacturer import Manufacturer, ManufacturerModelSeriali
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_manufacturer
|
||||
@pytest.mark.module_core
|
||||
class ManufacturerValidationAPI(
|
||||
TestCase,
|
||||
):
|
@ -1,6 +1,5 @@
|
||||
import django
|
||||
import pytest
|
||||
import unittest
|
||||
|
||||
from django.contrib.auth.models import Permission
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
@ -19,6 +18,8 @@ User = django.contrib.auth.get_user_model()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_manufacturer
|
||||
@pytest.mark.module_core
|
||||
class ManufacturerAPI(
|
||||
TestCase,
|
||||
APITenancyObject
|
@ -0,0 +1,84 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from core.viewsets.manufacturer import (
|
||||
Manufacturer,
|
||||
ViewSet,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_manufacturer
|
||||
class ViewsetTestCases(
|
||||
ModelViewSetInheritedCases,
|
||||
):
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'function' )
|
||||
def viewset(self):
|
||||
return ViewSet
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
return {
|
||||
'_model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'back_url': {
|
||||
'type': type(None),
|
||||
},
|
||||
'documentation': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'filterset_fields': {
|
||||
'value': [
|
||||
'organization'
|
||||
]
|
||||
},
|
||||
'model': {
|
||||
'value': Manufacturer
|
||||
},
|
||||
'model_documentation': {
|
||||
'type': type(None),
|
||||
},
|
||||
'queryset': {
|
||||
'type': type(None),
|
||||
},
|
||||
'serializer_class': {
|
||||
'type': type(None),
|
||||
},
|
||||
'search_fields': {
|
||||
'value': [
|
||||
'name'
|
||||
]
|
||||
},
|
||||
'view_description': {
|
||||
'value': 'Manufacturer(s) / Publishers'
|
||||
},
|
||||
'view_name': {
|
||||
'type': type(None),
|
||||
},
|
||||
'view_serializer_name': {
|
||||
'type': type(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
class KnowledgeBaseViewsetInheritedCases(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_core
|
||||
class KnowledgeBaseViewsetPyTest(
|
||||
ViewsetTestCases,
|
||||
):
|
||||
|
||||
pass
|
@ -1,27 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
from centurion.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
)
|
||||
|
||||
from core.models.manufacturer import Manufacturer
|
||||
|
||||
|
||||
class ManufacturerModelTestCases(
|
||||
TenancyObjectInheritedCases,
|
||||
):
|
||||
|
||||
kwargs_item_create = {
|
||||
'name': 'man'
|
||||
}
|
||||
|
||||
model = Manufacturer
|
||||
|
||||
|
||||
|
||||
class ManufacturerModelTest(
|
||||
ManufacturerModelTestCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
pass
|
@ -1,42 +0,0 @@
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
|
||||
from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
||||
|
||||
from core.viewsets.manufacturer import ViewSet
|
||||
|
||||
|
||||
|
||||
@pytest.mark.skip(reason = 'see #895, tests being refactored')
|
||||
class ManufacturerViewsetList(
|
||||
ModelViewSetInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
|
||||
viewset = ViewSet
|
||||
|
||||
route_name = 'v2:_api_manufacturer'
|
||||
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(self):
|
||||
"""Setup Test
|
||||
|
||||
1. make list request
|
||||
"""
|
||||
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
|
||||
client = Client()
|
||||
|
||||
url = reverse(
|
||||
self.route_name + '-list',
|
||||
kwargs = self.kwargs
|
||||
)
|
||||
|
||||
client.force_login(self.view_user)
|
||||
|
||||
self.http_options_response_list = client.options(url)
|
1
app/tests/fixtures/__init__.py
vendored
1
app/tests/fixtures/__init__.py
vendored
@ -77,6 +77,7 @@ from .model_company import (
|
||||
from .model_configgroup import (
|
||||
kwargs_configgroups,
|
||||
model_configgroups,
|
||||
serializer_configgroups,
|
||||
)
|
||||
|
||||
from .model_configgrouphost import (
|
||||
|
16
app/tests/fixtures/model_configgroup.py
vendored
16
app/tests/fixtures/model_configgroup.py
vendored
@ -2,6 +2,12 @@ import datetime
|
||||
import pytest
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
from config_management.serializers.config_group import (
|
||||
ConfigGroupBaseSerializer,
|
||||
ConfigGroupModelSerializer,
|
||||
ConfigGroupViewSerializer,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
@ -25,3 +31,13 @@ def kwargs_configgroups(django_db_blocker,
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def serializer_configgroups():
|
||||
|
||||
yield {
|
||||
'base': ConfigGroupBaseSerializer,
|
||||
'model': ConfigGroupModelSerializer,
|
||||
'view': ConfigGroupViewSerializer
|
||||
}
|
||||
|
Reference in New Issue
Block a user