@ -1,14 +1,18 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from access.models.entity import Entity
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture( scope = 'class')
|
@pytest.fixture( scope = 'class')
|
||||||
def model(request):
|
def model(model_entity):
|
||||||
|
|
||||||
request.cls.model = Entity
|
yield model_entity
|
||||||
|
|
||||||
yield request.cls.model
|
@pytest.fixture( scope = 'class')
|
||||||
|
def model_kwargs(request, kwargs_entity):
|
||||||
|
|
||||||
del request.cls.model
|
request.cls.kwargs_create_item = kwargs_entity.copy()
|
||||||
|
|
||||||
|
yield kwargs_entity.copy()
|
||||||
|
|
||||||
|
if hasattr(request.cls, 'kwargs_create_item'):
|
||||||
|
del request.cls.kwargs_create_item
|
||||||
|
@ -8,6 +8,7 @@ from api.tests.functional.test_functional_api_fields import (
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.model_entity
|
||||||
class EntityAPITestCases(
|
class EntityAPITestCases(
|
||||||
APIFieldsInheritedCases,
|
APIFieldsInheritedCases,
|
||||||
):
|
):
|
||||||
@ -71,6 +72,7 @@ class EntityAPIInheritedCases(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.module_access
|
||||||
class EntityAPIPyTest(
|
class EntityAPIPyTest(
|
||||||
EntityAPITestCases,
|
EntityAPITestCases,
|
||||||
):
|
):
|
||||||
|
@ -4,271 +4,112 @@ from django.db import models
|
|||||||
|
|
||||||
from access.models.entity import Entity
|
from access.models.entity import Entity
|
||||||
|
|
||||||
from centurion.tests.unit.test_unit_models import (
|
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
|
||||||
PyTestTenancyObjectInheritedCases,
|
CenturionAbstractModelInheritedCases
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.model_entity
|
||||||
class EntityModelTestCases(
|
class EntityModelTestCases(
|
||||||
PyTestTenancyObjectInheritedCases,
|
CenturionAbstractModelInheritedCases
|
||||||
):
|
):
|
||||||
|
|
||||||
base_model = Entity
|
|
||||||
|
|
||||||
kwargs_create_item: dict = {}
|
@property
|
||||||
|
def parameterized_class_attributes(self):
|
||||||
|
|
||||||
sub_model_type = 'entity'
|
return {
|
||||||
"""Sub Model Type
|
'_is_submodel': {
|
||||||
|
'value': False
|
||||||
sub-models must have this attribute defined in `ModelName.Meta.sub_model_type`
|
},
|
||||||
"""
|
'model_tag': {
|
||||||
|
'type': str,
|
||||||
|
'value': 'entity'
|
||||||
|
},
|
||||||
|
'url_model_name': {
|
||||||
|
'type': str,
|
||||||
|
'value': 'entity'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
parameterized_fields: dict = {
|
@property
|
||||||
"entity_type": {
|
def parameterized_fields(self):
|
||||||
'field_type': models.fields.CharField,
|
|
||||||
'field_parameter_default_exists': False,
|
return {
|
||||||
# 'field_parameter_default_value': 'entity',
|
'entity_type': {
|
||||||
'field_parameter_verbose_name_type': str
|
'blank': False,
|
||||||
|
'default': models.fields.NOT_PROVIDED,
|
||||||
|
'field_type': models.CharField,
|
||||||
|
'length': 50,
|
||||||
|
'null': False,
|
||||||
|
'unique': True,
|
||||||
|
},
|
||||||
|
'modified': {
|
||||||
|
'blank': False,
|
||||||
|
'default': models.fields.NOT_PROVIDED,
|
||||||
|
'field_type': models.DateTimeField,
|
||||||
|
'null': False,
|
||||||
|
'unique': False,
|
||||||
},
|
},
|
||||||
# "asset_number": {
|
|
||||||
# 'field_type': models.fields.CharField,
|
|
||||||
# 'field_parameter_default_exists': False,
|
|
||||||
# 'field_parameter_verbose_name_type': str,
|
|
||||||
# },
|
|
||||||
# "serial_number": {
|
|
||||||
# 'field_type': models.fields.CharField,
|
|
||||||
# 'field_parameter_default_exists': False,
|
|
||||||
# 'field_parameter_verbose_name_type': str,
|
|
||||||
# }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_class_inherits_entity(self, model):
|
||||||
@pytest.fixture( scope = 'class')
|
|
||||||
def setup_model(self,
|
|
||||||
request,
|
|
||||||
model,
|
|
||||||
django_db_blocker,
|
|
||||||
organization_one,
|
|
||||||
organization_two
|
|
||||||
):
|
|
||||||
|
|
||||||
with django_db_blocker.unblock():
|
|
||||||
|
|
||||||
request.cls.organization = organization_one
|
|
||||||
|
|
||||||
request.cls.different_organization = organization_two
|
|
||||||
|
|
||||||
kwargs_create_item = {}
|
|
||||||
|
|
||||||
for base in reversed(request.cls.__mro__):
|
|
||||||
|
|
||||||
if hasattr(base, 'kwargs_create_item'):
|
|
||||||
|
|
||||||
if base.kwargs_create_item is None:
|
|
||||||
|
|
||||||
continue
|
|
||||||
|
|
||||||
kwargs_create_item.update(**base.kwargs_create_item)
|
|
||||||
|
|
||||||
|
|
||||||
if len(kwargs_create_item) > 0:
|
|
||||||
|
|
||||||
request.cls.kwargs_create_item = kwargs_create_item
|
|
||||||
|
|
||||||
|
|
||||||
if 'organization' not in request.cls.kwargs_create_item:
|
|
||||||
|
|
||||||
request.cls.kwargs_create_item.update({
|
|
||||||
'organization': request.cls.organization
|
|
||||||
})
|
|
||||||
|
|
||||||
yield
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture( scope = 'class', autouse = True)
|
|
||||||
def class_setup(self,
|
|
||||||
setup_model,
|
|
||||||
create_model,
|
|
||||||
):
|
|
||||||
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_class_inherits_entity(self):
|
|
||||||
""" Class inheritence
|
""" Class inheritence
|
||||||
|
|
||||||
TenancyObject must inherit SaveHistory
|
TenancyObject must inherit SaveHistory
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert issubclass(self.model, Entity)
|
assert issubclass(model, Entity)
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_type_history_app_label(self):
|
def test_function_value_get_related_model(self, model, model_instance):
|
||||||
"""Attribute Type
|
"""Function test
|
||||||
|
|
||||||
history_app_label is of type str
|
Confirm function `get_related_model` is of the sub-model type
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert type(self.model.history_app_label) is str
|
assert type(model_instance.get_related_model()) == model
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_value_history_app_label(self):
|
def test_attribute_type_kb_model_name(self, model):
|
||||||
"""Attribute Type
|
|
||||||
|
|
||||||
history_app_label has been set, override this test case with the value
|
|
||||||
of attribute `history_app_label`
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert self.model.history_app_label == 'access'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_type_history_model_name(self):
|
|
||||||
"""Attribute Type
|
|
||||||
|
|
||||||
history_model_name is of type str
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert type(self.model.history_model_name) is str
|
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_value_history_model_name(self):
|
|
||||||
"""Attribute Type
|
|
||||||
|
|
||||||
history_model_name has been set, override this test case with the value
|
|
||||||
of attribute `history_model_name`
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert self.model.history_model_name == 'entity'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_type_kb_model_name(self):
|
|
||||||
"""Attribute Type
|
"""Attribute Type
|
||||||
|
|
||||||
kb_model_name is of type str
|
kb_model_name is of type str
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert type(self.model.kb_model_name) is str
|
assert type(model.kb_model_name) is str
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_value_kb_model_name(self):
|
def test_attribute_value_kb_model_name(self, model):
|
||||||
"""Attribute Type
|
"""Attribute Type
|
||||||
|
|
||||||
kb_model_name has been set, override this test case with the value
|
kb_model_name has been set, override this test case with the value
|
||||||
of attribute `kb_model_name`
|
of attribute `kb_model_name`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert self.model.kb_model_name == 'entity'
|
assert model.kb_model_name == 'entity'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_type_note_basename(self):
|
|
||||||
"""Attribute Type
|
|
||||||
|
|
||||||
note_basename is of type str
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert type(self.model.note_basename) is str
|
|
||||||
|
|
||||||
|
|
||||||
def test_attribute_value_note_basename(self):
|
|
||||||
"""Attribute Type
|
|
||||||
|
|
||||||
note_basename has been set, override this test case with the value
|
|
||||||
of attribute `note_basename`
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert self.model.note_basename == '_api_v2_entity_note'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def test_function_is_property_get_model_type(self):
|
|
||||||
# """Function test
|
|
||||||
|
|
||||||
# Confirm function `get_model_type` is a property
|
|
||||||
# """
|
|
||||||
|
|
||||||
# assert type(self.model.get_model_type) is property
|
|
||||||
|
|
||||||
|
|
||||||
# def test_function_value_get_model_type(self):
|
|
||||||
# """Function test
|
|
||||||
|
|
||||||
# Confirm function `get_model_type` does not have a value of None
|
|
||||||
# value should be equaul to Meta.sub_model_type
|
|
||||||
# """
|
|
||||||
|
|
||||||
# assert self.item.get_model_type == self.item._meta.sub_model_type
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_function_value_get_related_model(self):
|
|
||||||
"""Function test
|
|
||||||
|
|
||||||
Confirm function `get_related_model` is of the sub-model type
|
|
||||||
"""
|
|
||||||
|
|
||||||
assert type(self.item.get_related_model()) == self.model
|
|
||||||
|
|
||||||
|
|
||||||
def test_function_value_get_url(self):
|
|
||||||
|
|
||||||
assert self.item.get_url() == '/api/v2/access/entity/' + str(self.item.id)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EntityModelInheritedCases(
|
class EntityModelInheritedCases(
|
||||||
EntityModelTestCases,
|
EntityModelTestCases,
|
||||||
):
|
):
|
||||||
"""Sub-Ticket Test Cases
|
pass
|
||||||
|
|
||||||
Test Cases for Ticket models that inherit from model Entity
|
|
||||||
"""
|
|
||||||
|
|
||||||
kwargs_create_item: dict = {}
|
|
||||||
|
|
||||||
model = None
|
|
||||||
|
|
||||||
|
|
||||||
sub_model_type = None
|
|
||||||
"""Ticket Sub Model Type
|
|
||||||
|
|
||||||
Ticket sub-models must have this attribute defined in `ModelNam.Meta.sub_model_type`
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
# def test_function_value_get_model_type(self):
|
|
||||||
# """Function test
|
|
||||||
|
|
||||||
# Confirm function `get_model_type` does not have a value of None
|
|
||||||
# value should be equaul to Meta.sub_model_type
|
|
||||||
# """
|
|
||||||
|
|
||||||
# assert self.item.get_model_type == self.item._meta.sub_model_type
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.module_access
|
||||||
class EntityModelPyTest(
|
class EntityModelPyTest(
|
||||||
EntityModelTestCases,
|
EntityModelTestCases,
|
||||||
):
|
):
|
||||||
|
|
||||||
|
def test_function_value_get_related_model(self, model_instance):
|
||||||
def test_function_value_get_related_model(self):
|
|
||||||
"""Function test
|
"""Function test
|
||||||
|
|
||||||
Confirm function `get_related_model` is None for base model
|
Confirm function `get_related_model` is None for base model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
assert self.item.get_related_model() is None
|
assert model_instance.get_related_model() is None
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
from django.test import Client, TestCase
|
from django.test import Client, TestCase
|
||||||
|
|
||||||
from rest_framework.reverse import reverse
|
from rest_framework.reverse import reverse
|
||||||
@ -12,6 +14,7 @@ from api.tests.unit.test_unit_common_viewset import ModelViewSetInheritedCases
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.model_entity
|
||||||
class ViewsetTestCases(
|
class ViewsetTestCases(
|
||||||
ModelViewSetInheritedCases,
|
ModelViewSetInheritedCases,
|
||||||
):
|
):
|
||||||
@ -70,6 +73,7 @@ class EntityViewsetInheritedCases(
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.module_access
|
||||||
class EntityViewsetTest(
|
class EntityViewsetTest(
|
||||||
ViewsetTestCases,
|
ViewsetTestCases,
|
||||||
TestCase,
|
TestCase,
|
||||||
|
5
app/tests/fixtures/__init__.py
vendored
5
app/tests/fixtures/__init__.py
vendored
@ -102,6 +102,11 @@ from .model_devicetype import (
|
|||||||
model_devicetype,
|
model_devicetype,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from .model_entity import (
|
||||||
|
kwargs_entity,
|
||||||
|
model_entity,
|
||||||
|
)
|
||||||
|
|
||||||
from .model_externallink import (
|
from .model_externallink import (
|
||||||
kwargs_externallink,
|
kwargs_externallink,
|
||||||
model_externallink,
|
model_externallink,
|
||||||
|
26
app/tests/fixtures/model_entity.py
vendored
Normal file
26
app/tests/fixtures/model_entity.py
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import datetime
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from access.models.entity import Entity
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture( scope = 'class')
|
||||||
|
def model_entity():
|
||||||
|
|
||||||
|
yield Entity
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture( scope = 'class')
|
||||||
|
def kwargs_entity( kwargs_centurionmodel ):
|
||||||
|
|
||||||
|
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||||
|
random_str = str(random_str).replace(
|
||||||
|
' ', '').replace(':', '').replace('+', '').replace('.', '')
|
||||||
|
|
||||||
|
kwargs = {
|
||||||
|
**kwargs_centurionmodel.copy(),
|
||||||
|
'entity_type': 'entity',
|
||||||
|
}
|
||||||
|
|
||||||
|
yield kwargs.copy()
|
Reference in New Issue
Block a user