refactor(itam): Update Test Suite for ITAMAssetBase model
ref: #862 #858
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from accounting.tests.functional.asset_base.test_functional_asset_base_metadata import AssetBaseMetadataInheritedCases
|
||||
@ -6,6 +8,7 @@ from itam.models.itam_asset_base import ITAMAssetBase
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class MetadataTestCases(
|
||||
AssetBaseMetadataInheritedCases,
|
||||
):
|
||||
@ -38,6 +41,7 @@ class ITAMAssetBaseMetadataInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBaseMetadataTest(
|
||||
MetadataTestCases,
|
||||
TestCase,
|
||||
|
@ -1,7 +1,10 @@
|
||||
import pytest
|
||||
|
||||
from accounting.tests.functional.asset_base.test_functional_asset_base_permission import AssetBasePermissionsAPIInheritedCases
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class PermissionsAPITestCases(
|
||||
AssetBasePermissionsAPIInheritedCases,
|
||||
):
|
||||
@ -40,6 +43,7 @@ class ITAMAssetBasePermissionsAPIInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBasePermissionsAPIPyTest(
|
||||
PermissionsAPITestCases,
|
||||
):
|
||||
|
@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
|
||||
from accounting.tests.functional.asset_base.test_functional_asset_base_serializer import AssetBaseSerializerInheritedCases
|
||||
|
||||
@ -25,6 +26,7 @@ class MockView:
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class ITAMAssetBaseSerializerTestCases(
|
||||
AssetBaseSerializerInheritedCases
|
||||
):
|
||||
@ -54,6 +56,7 @@ class ITAMAssetBaseSerializerInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBaseSerializerPyTest(
|
||||
ITAMAssetBaseSerializerTestCases,
|
||||
):
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from accounting.tests.functional.asset_base.test_functional_asset_base_viewset import AssetBaseViewSetInheritedCases
|
||||
@ -6,6 +8,7 @@ from itam.models.itam_asset_base import ITAMAssetBase
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class ViewSetTestCases(
|
||||
AssetBaseViewSetInheritedCases
|
||||
):
|
||||
@ -42,6 +45,7 @@ class ITAMAssetBaseViewSetInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBaseViewSetTest(
|
||||
ViewSetTestCases,
|
||||
TestCase,
|
||||
|
@ -1,9 +1,12 @@
|
||||
import pytest
|
||||
|
||||
from accounting.tests.unit.asset_base.test_unit_asset_base_api_fields import (
|
||||
AssetBaseAPIInheritedCases
|
||||
)
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class ITAMAssetBaseAPITestCases(
|
||||
AssetBaseAPIInheritedCases,
|
||||
):
|
||||
@ -29,6 +32,7 @@ class ITAMAssetBaseAPIInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBaseAPIPyTest(
|
||||
ITAMAssetBaseAPITestCases,
|
||||
):
|
||||
|
@ -1,177 +1,77 @@
|
||||
import pytest
|
||||
|
||||
from django.db import models
|
||||
|
||||
from accounting.tests.unit.asset_base.test_unit_asset_base_model import AssetBaseModelInheritedCases
|
||||
from accounting.tests.unit.asset_base.test_unit_asset_base_model import (
|
||||
AssetBaseModelInheritedCases,
|
||||
)
|
||||
|
||||
from itam.models.itam_asset_base import ITAMAssetBase
|
||||
|
||||
|
||||
|
||||
class ITAMAssetBaseModelTestCases(
|
||||
AssetBaseModelInheritedCases,
|
||||
@pytest.mark.model_itamassetbase
|
||||
class ITAMAssetModelTestCases(
|
||||
AssetBaseModelInheritedCases
|
||||
):
|
||||
|
||||
kwargs_create_item: dict = {}
|
||||
|
||||
it_asset_base_model = ITAMAssetBase
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
sub_model_type = 'itam_base'
|
||||
"""Sub Model Type
|
||||
|
||||
sub-models must have this attribute defined in `ModelName.Meta.sub_model_type`
|
||||
"""
|
||||
return {
|
||||
'_is_submodel': {
|
||||
'value': True
|
||||
},
|
||||
'app_namespace': {
|
||||
'type': type(None),
|
||||
'value': None
|
||||
},
|
||||
'model_tag': {
|
||||
'type': str,
|
||||
'value': 'it_asset'
|
||||
},
|
||||
'url_model_name': {
|
||||
'type': str,
|
||||
'value': 'itamassetbase'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
parameterized_fields: dict = {
|
||||
"itam_type": {
|
||||
'field_type': models.fields.CharField,
|
||||
'field_parameter_default_exists': True,
|
||||
'field_parameter_default_value': ITAMAssetBase._meta.itam_sub_model_type,
|
||||
'field_parameter_verbose_name_type': str
|
||||
@property
|
||||
def parameterized_model_fields(self):
|
||||
|
||||
return {
|
||||
'itam_type': {
|
||||
'blank': True,
|
||||
'default': 'itam_base',
|
||||
'field_type': models.CharField,
|
||||
'max_length': 30,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
def test_class_inherits_itam_assetbase(self):
|
||||
def test_class_inherits_itamassetbase(self, model):
|
||||
""" Class inheritence
|
||||
|
||||
TenancyObject must inherit SaveHistory
|
||||
"""
|
||||
|
||||
assert issubclass(self.model, ITAMAssetBase)
|
||||
|
||||
|
||||
def test_attribute_meta_exists_itam_sub_model_type(self):
|
||||
"""Attribute check
|
||||
|
||||
meta.itam_sub_model_type must exist
|
||||
"""
|
||||
|
||||
assert hasattr(self.model()._meta, 'itam_sub_model_type')
|
||||
|
||||
|
||||
def test_sanity_is_it_asset_sub_model(self):
|
||||
"""Sanity Test
|
||||
|
||||
This test ensures that the model being tested `self.model` is a
|
||||
sub-model of `self.it_asset_base_model`.
|
||||
This test is required as the same viewset is used for all sub-models
|
||||
of `ITAMAssetBase`
|
||||
"""
|
||||
|
||||
assert issubclass(self.model, self.it_asset_base_model)
|
||||
|
||||
|
||||
def test_attribute_meta_type_itam_sub_model_type(self):
|
||||
"""Attribute type
|
||||
|
||||
meta.itam_sub_model_type must be of type str
|
||||
"""
|
||||
|
||||
assert type(self.model()._meta.itam_sub_model_type) is str
|
||||
assert issubclass(model, ITAMAssetBase)
|
||||
|
||||
|
||||
|
||||
def test_attribute_type_app_namespace(self):
|
||||
"""Attribute Type
|
||||
|
||||
app_namespace is of type str
|
||||
"""
|
||||
|
||||
assert self.model.app_namespace is None
|
||||
|
||||
|
||||
def test_attribute_value_app_namespace(self):
|
||||
"""Attribute Type
|
||||
|
||||
app_namespace has been set, override this test case with the value
|
||||
of attribute `app_namespace`
|
||||
"""
|
||||
|
||||
assert self.model.app_namespace is None
|
||||
|
||||
|
||||
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 == 'accounting:_api_v2_asset_note'
|
||||
|
||||
|
||||
def test_function_is_property_get_itam_model_type(self):
|
||||
"""Function test
|
||||
|
||||
Confirm function `get_itam_model_type` is a property
|
||||
"""
|
||||
|
||||
assert type(self.model.get_itam_model_type) is property
|
||||
|
||||
|
||||
def test_function_value_get_itam_model_type(self):
|
||||
"""Function test
|
||||
|
||||
Confirm function `get_itam_model_type` is a property
|
||||
"""
|
||||
|
||||
assert self.item.get_itam_model_type is None
|
||||
|
||||
|
||||
def test_function_value_get_url(self):
|
||||
|
||||
assert self.item.get_url() == '/api/v2/itam/it_asset/' + str(self.item.id)
|
||||
|
||||
|
||||
|
||||
class ITAMAssetBaseModelInheritedCases(
|
||||
ITAMAssetBaseModelTestCases,
|
||||
class ITAMAssetModelInheritedCases(
|
||||
ITAMAssetModelTestCases,
|
||||
):
|
||||
"""Sub-Ticket Test Cases
|
||||
|
||||
Test Cases for Ticket models that inherit from model AssetBase
|
||||
"""
|
||||
|
||||
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_not_None_get_itam_model_type(self):
|
||||
"""Function test
|
||||
|
||||
Confirm function `get_itam_model_type` is a property
|
||||
"""
|
||||
|
||||
assert self.item.get_itam_model_type is not None
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ITAMAssetBaseModelPyTest(
|
||||
ITAMAssetBaseModelTestCases,
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetModelPyTest(
|
||||
ITAMAssetModelTestCases,
|
||||
):
|
||||
|
||||
def test_function_value_get_related_model(self):
|
||||
"""Function test
|
||||
|
||||
Confirm function `get_related_model` is None for base model
|
||||
"""
|
||||
|
||||
assert self.item.get_related_model() is None
|
||||
pass
|
||||
|
@ -1,3 +1,5 @@
|
||||
import pytest
|
||||
|
||||
from django.test import Client, TestCase
|
||||
|
||||
from rest_framework.reverse import reverse
|
||||
@ -22,6 +24,7 @@ from itam.models.itam_asset_base import ITAMAssetBase
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_itamassetbase
|
||||
class ITAMAssetBaseViewsetTestCases(
|
||||
AssetBaseViewsetInheritedCases,
|
||||
):
|
||||
@ -45,6 +48,7 @@ class ITAMAssetBaseViewsetInheritedCases(
|
||||
|
||||
|
||||
|
||||
@pytest.mark.module_accounting
|
||||
class ITAMAssetBaseViewsetTest(
|
||||
ITAMAssetBaseViewsetTestCases,
|
||||
TestCase,
|
||||
|
10
app/tests/fixtures/__init__.py
vendored
10
app/tests/fixtures/__init__.py
vendored
@ -18,6 +18,11 @@ from .model_appsettings import (
|
||||
model_appsettings,
|
||||
)
|
||||
|
||||
from .model_assetbase import (
|
||||
kwargs_assetbase,
|
||||
model_assetbase,
|
||||
)
|
||||
|
||||
from .model_centurionaudit import (
|
||||
kwargs_centurionaudit,
|
||||
model_centurionaudit,
|
||||
@ -160,6 +165,11 @@ from .model_instance import (
|
||||
model_instance
|
||||
)
|
||||
|
||||
from .model_itamassetbase import (
|
||||
kwargs_itamassetbase,
|
||||
model_itamassetbase,
|
||||
)
|
||||
|
||||
from .model_knowledgebase import (
|
||||
kwargs_knowledgebase,
|
||||
model_knowledgebase,
|
||||
|
24
app/tests/fixtures/model_itamassetbase.py
vendored
Normal file
24
app/tests/fixtures/model_itamassetbase.py
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
import datetime
|
||||
import pytest
|
||||
|
||||
from itam.models.itam_asset_base import ITAMAssetBase
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def model_itamassetbase():
|
||||
|
||||
yield ITAMAssetBase
|
||||
|
||||
|
||||
@pytest.fixture( scope = 'class')
|
||||
def kwargs_itamassetbase( kwargs_assetbase, model_itamassetbase ):
|
||||
|
||||
random_str = str(datetime.datetime.now(tz=datetime.timezone.utc))
|
||||
random_str = str(random_str).replace(
|
||||
' ', '').replace(':', '').replace('+', '').replace('.', '')
|
||||
|
||||
kwargs = {
|
||||
**kwargs_assetbase.copy(),
|
||||
# 'asset_type': (model_itamassetbase._meta.sub_model_type, model_itamassetbase._meta.verbose_name),
|
||||
}
|
||||
|
||||
yield kwargs.copy()
|
@ -1125,6 +1125,7 @@ markers = [
|
||||
"model_githubrepository: Selects tests for model `github repository`",
|
||||
"model_gitlabrepository: Selects tests for model `gitlab repository`",
|
||||
"model_gitrepository: Selects tests for model `git repository`",
|
||||
"model_itamassetbase: Selects tests for model ITAM Asset Base.",
|
||||
"model_knowledgebase: Selects Knowledge base tests.",
|
||||
"model_knowledgebasecategory: Selects Knowledge base category tests.",
|
||||
"model_manufacturer: Select all manufacturer tests.",
|
||||
|
Reference in New Issue
Block a user