test(config_management): Completed ConfigGroup Model Tests

ref: #804 #795
This commit is contained in:
2025-06-07 15:42:56 +09:30
parent 0e604228aa
commit 8c4e5d5c1d
4 changed files with 69 additions and 51 deletions

View File

@ -443,7 +443,7 @@ class ConfigGroupSoftware(
# This model is not intended to be viewable on it's own page
# as it's a sub model for config groups
page_layout: dict = []
page_layout: list = []
table_fields: list = [

View File

@ -0,0 +1,19 @@
import pytest
@pytest.fixture( scope = 'class')
def model(model_configgroup):
yield model_configgroup
@pytest.fixture( scope = 'class', autouse = True)
def model_kwargs(request, kwargs_configgroup):
request.cls.kwargs_create_item = kwargs_configgroup.copy()
yield kwargs_configgroup.copy()
if hasattr(request.cls, 'kwargs_create_item'):
del request.cls.kwargs_create_item

View File

@ -9,80 +9,80 @@ from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model impor
class Old:
# class Old:
kwargs_item_create = {
'name': 'one',
'config': dict({"key": "one", "existing": "dont_over_write"})
}
# kwargs_item_create = {
# 'name': 'one',
# 'config': dict({"key": "one", "existing": "dont_over_write"})
# }
model = ConfigGroups
# model = ConfigGroups
@classmethod
def setUpTestData(self):
"""Setup Test
# @classmethod
# def setUpTestData(self):
# """Setup Test
1. Create an organization for user and item
2. Create an item
# 1. Create an organization for user and item
# 2. Create an item
"""
# """
self.organization = Organization.objects.create(name='test_org')
# self.organization = Organization.objects.create(name='test_org')
super().setUpTestData()
# super().setUpTestData()
self.second_item = self.model.objects.create(
organization = self.organization,
name = 'one_two',
config = dict({"key": "two"}),
parent = self.item
)
# self.second_item = self.model.objects.create(
# organization = self.organization,
# name = 'one_two',
# config = dict({"key": "two"}),
# parent = self.item
# )
def test_config_groups_count_child_groups(self):
""" Test function count_children """
# def test_config_groups_count_child_groups(self):
# """ Test function count_children """
assert self.item.count_children() == 1
# assert self.item.count_children() == 1
def test_config_groups_rendered_config_not_empty(self):
""" Rendered Config must be returned """
# def test_config_groups_rendered_config_not_empty(self):
# """ Rendered Config must be returned """
assert self.item.config is not None
# assert self.item.config is not None
def test_config_groups_rendered_config_is_dict(self):
""" Rendered Config is a string """
# def test_config_groups_rendered_config_is_dict(self):
# """ Rendered Config is a string """
assert type(self.item.render_config()) is dict
# assert type(self.item.render_config()) is dict
def test_config_groups_rendered_config_is_correct(self):
""" Rendered Config is correct """
# def test_config_groups_rendered_config_is_correct(self):
# """ Rendered Config is correct """
assert self.item.config['key'] == 'one'
# assert self.item.config['key'] == 'one'
def test_config_groups_rendered_config_inheritence_overwrite(self):
""" rendered config from parent group merged correctly """
# def test_config_groups_rendered_config_inheritence_overwrite(self):
# """ rendered config from parent group merged correctly """
assert self.second_item.config['key'] == 'two'
# assert self.second_item.config['key'] == 'two'
def test_config_groups_rendered_config_inheritence_existing_key_present(self):
""" rendered config from parent group merge existing key present
# def test_config_groups_rendered_config_inheritence_existing_key_present(self):
# """ rendered config from parent group merge existing key present
during merge, a key that doesn't exist in the child group that exists in the
parent group should be within the child groups rendered config
"""
# during merge, a key that doesn't exist in the child group that exists in the
# parent group should be within the child groups rendered config
# """
assert self.second_item.config['key'] == 'two'
# assert self.second_item.config['key'] == 'two'
@pytest.mark.skip(reason="to be written")
def test_config_groups_config_keys_valid_ansible_variable():
""" All config keys must be valid ansible variables """
pass
# @pytest.mark.skip(reason="to be written")
# def test_config_groups_config_keys_valid_ansible_variable():
# """ All config keys must be valid ansible variables """
# pass
@ -112,11 +112,11 @@ class ConfigGroupModelTestCases(
'unique': False,
},
'name': {
'blank': True,
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.TextField,
'max_length': 50,
'null': True,
'null': False,
'unique': False,
},
'config': {
@ -127,10 +127,10 @@ class ConfigGroupModelTestCases(
'unique': False,
},
'hosts': {
'blank': False,
'blank': True,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ManyToManyField,
'null': True,
'null': False,
'unique': False,
},
'modified': {

View File

@ -191,7 +191,6 @@ class CenturionAbstractModelTestCases(
Ensure method `get_url_kwargs` returns the correct value.
"""
model_instance.id = 1
url = model_instance.get_url_kwargs()