refactor(access): Update Test Suite for Company model
ref: #839 #845 #760
This commit is contained in:
@ -1,14 +1,20 @@
|
||||
import pytest
|
||||
|
||||
from access.models.company_base import Company
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model(request):
|
||||
def model(model_company):
|
||||
|
||||
request.cls.model = Company
|
||||
yield model_company
|
||||
|
||||
yield request.cls.model
|
||||
|
||||
del request.cls.model
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_kwargs(request, kwargs_company):
|
||||
|
||||
request.cls.kwargs_create_item = kwargs_company.copy()
|
||||
|
||||
yield kwargs_company.copy()
|
||||
|
||||
if hasattr(request.cls, 'kwargs_create_item'):
|
||||
del request.cls.kwargs_create_item
|
||||
|
@ -1,9 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from access.tests.unit.entity.test_unit_entity_api_fields import (
|
||||
EntityAPIInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_company
|
||||
class CompanyAPITestCases(
|
||||
EntityAPIInheritedCases,
|
||||
):
|
||||
@ -30,6 +33,7 @@ class CompanyAPIInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class CompanyAPIPyTest(
|
||||
CompanyAPITestCases,
|
||||
):
|
||||
|
@ -3,20 +3,17 @@ import pytest
|
||||
from django.db import models
|
||||
|
||||
from access.models.company_base import Company
|
||||
|
||||
from access.tests.unit.entity.test_unit_entity_model import (
|
||||
EntityModelInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_company
|
||||
class CompanyModelTestCases(
|
||||
EntityModelInheritedCases,
|
||||
):
|
||||
|
||||
kwargs_create_item: dict = {
|
||||
'name': 'Ian',
|
||||
}
|
||||
|
||||
sub_model_type = 'company'
|
||||
"""Sub Model Type
|
||||
@ -25,49 +22,43 @@ class CompanyModelTestCases(
|
||||
"""
|
||||
|
||||
|
||||
parameterized_fields: dict = {
|
||||
"name": {
|
||||
'field_type': models.fields.CharField,
|
||||
'field_parameter_default_exists': False,
|
||||
'field_parameter_verbose_name_type': str,
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'_is_submodel': {
|
||||
'value': True
|
||||
},
|
||||
'url_model_name': {
|
||||
'type': str,
|
||||
'value': 'entity'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_fields(self):
|
||||
|
||||
return {
|
||||
'name': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.CharField,
|
||||
'length': 80,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
def test_class_inherits_company(self):
|
||||
def test_class_inherits_company(self, model):
|
||||
""" Class inheritence
|
||||
|
||||
TenancyObject must inherit SaveHistory
|
||||
"""
|
||||
|
||||
assert issubclass(self.model, Company)
|
||||
|
||||
|
||||
def test_attribute_value_history_app_label(self):
|
||||
"""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_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 == 'company'
|
||||
|
||||
|
||||
|
||||
def test_function_value_get_url(self):
|
||||
|
||||
assert self.item.get_url() == '/api/v2/access/entity/company/' + str(self.item.id)
|
||||
assert issubclass(model, Company)
|
||||
|
||||
|
||||
|
||||
@ -78,28 +69,20 @@ class CompanyModelInheritedCases(
|
||||
|
||||
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`
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class CompanyModelPyTest(
|
||||
CompanyModelTestCases,
|
||||
):
|
||||
|
||||
|
||||
def test_function_value_get_related_model(self):
|
||||
def test_function_value_get_related_model(self, model_instance):
|
||||
"""Function test
|
||||
|
||||
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 TestCase
|
||||
|
||||
from access.models.company_base import Company
|
||||
@ -7,6 +9,7 @@ from access.tests.unit.entity.test_unit_entity_viewset import (
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_company
|
||||
class ViewsetTestCases(
|
||||
EntityViewsetInheritedCases,
|
||||
):
|
||||
@ -28,6 +31,7 @@ class CompanyViewsetInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_access
|
||||
class CompanyViewsetTest(
|
||||
ViewsetTestCases,
|
||||
TestCase,
|
||||
|
5
app/tests/fixtures/__init__.py
vendored
5
app/tests/fixtures/__init__.py
vendored
@ -58,6 +58,11 @@ from .model_clustertype import (
|
||||
model_clustertype,
|
||||
)
|
||||
|
||||
from .model_company import (
|
||||
kwargs_company,
|
||||
model_company,
|
||||
)
|
||||
|
||||
from .model_configgroup import (
|
||||
kwargs_configgroups,
|
||||
model_configgroups,
|
||||
|
26
app/tests/fixtures/model_company.py
vendored
Normal file
26
app/tests/fixtures/model_company.py
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import datetime
|
||||
import pytest
|
||||
|
||||
from access.models.company_base import Company
|
||||
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_company():
|
||||
|
||||
yield Company
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_company( kwargs_entity ):
|
||||
|
||||
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||
random_str = str(random_str).replace(
|
||||
' ', '').replace(':', '').replace('+', '').replace('.', '')
|
||||
|
||||
kwargs = {
|
||||
**kwargs_entity.copy(),
|
||||
'name': 'c' + random_str,
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
Reference in New Issue
Block a user