refactor(config_management): Add ConfigGroup Model Tests
ref: #804 #795
This commit is contained in:
@ -0,0 +1,40 @@
|
||||
# Generated by Django 5.1.9 on 2025-06-07 03:57
|
||||
|
||||
import config_management.models.groups
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("config_management", "0011_remove_configgroupsoftware_is_global_and_more"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="configgroups",
|
||||
name="config",
|
||||
field=models.JSONField(
|
||||
blank=True,
|
||||
help_text="Configuration for this Group",
|
||||
null=True,
|
||||
validators=[
|
||||
config_management.models.groups.ConfigGroups.validate_config_keys_not_reserved
|
||||
],
|
||||
verbose_name="Configuration",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="configgroups",
|
||||
name="parent",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="Parent of this Group",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to="config_management.configgroups",
|
||||
verbose_name="Parent Group",
|
||||
),
|
||||
),
|
||||
]
|
@ -20,6 +20,7 @@ class ConfigGroups(
|
||||
CenturionModel,
|
||||
):
|
||||
|
||||
model_tag = 'config_group'
|
||||
|
||||
class Meta:
|
||||
|
||||
@ -55,10 +56,9 @@ class ConfigGroups(
|
||||
parent = models.ForeignKey(
|
||||
'self',
|
||||
blank= True,
|
||||
default = None,
|
||||
help_text = 'Parent of this Group',
|
||||
null = True,
|
||||
on_delete=models.SET_DEFAULT,
|
||||
on_delete = models.PROTECT,
|
||||
verbose_name = 'Parent Group'
|
||||
)
|
||||
|
||||
@ -74,7 +74,6 @@ class ConfigGroups(
|
||||
|
||||
config = models.JSONField(
|
||||
blank = True,
|
||||
default = None,
|
||||
help_text = 'Configuration for this Group',
|
||||
null = True,
|
||||
validators=[ validate_config_keys_not_reserved ],
|
||||
|
@ -1,21 +1,16 @@
|
||||
import pytest
|
||||
|
||||
from django.test import TestCase
|
||||
from django.db import models
|
||||
|
||||
from access.models.tenant import Tenant as Organization
|
||||
|
||||
from centurion.tests.unit.test_unit_models import (
|
||||
TenancyObjectInheritedCases
|
||||
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
|
||||
CenturionAbstractModelInheritedCases
|
||||
)
|
||||
|
||||
from config_management.models.groups import ConfigGroups
|
||||
|
||||
|
||||
class Old:
|
||||
|
||||
class ConfigGroupsModel(
|
||||
TenancyObjectInheritedCases,
|
||||
TestCase,
|
||||
):
|
||||
kwargs_item_create = {
|
||||
'name': 'one',
|
||||
'config': dict({"key": "one", "existing": "dont_over_write"})
|
||||
@ -44,8 +39,6 @@ class ConfigGroupsModel(
|
||||
parent = self.item
|
||||
)
|
||||
|
||||
|
||||
|
||||
def test_config_groups_count_child_groups(self):
|
||||
""" Test function count_children """
|
||||
|
||||
@ -91,3 +84,74 @@ class ConfigGroupsModel(
|
||||
""" All config keys must be valid ansible variables """
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@pytest.mark.model_config_group
|
||||
class ConfigGroupModelTestCases(
|
||||
CenturionAbstractModelInheritedCases
|
||||
):
|
||||
|
||||
|
||||
@property
|
||||
def parameterized_class_attributes(self):
|
||||
|
||||
return {
|
||||
'model_tag': {
|
||||
'type': str,
|
||||
'value': 'config_group'
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
parameterized_model_fields = {
|
||||
'parent': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ForeignKey,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'name': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.TextField,
|
||||
'max_length': 50,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'config': {
|
||||
'blank': True,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.JSONField,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'hosts': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.ManyToManyField,
|
||||
'null': True,
|
||||
'unique': False,
|
||||
},
|
||||
'modified': {
|
||||
'blank': False,
|
||||
'default': models.fields.NOT_PROVIDED,
|
||||
'field_type': models.DateTimeField,
|
||||
'null': False,
|
||||
'unique': False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
class ConfigGroupModelInheritedCases(
|
||||
ConfigGroupModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
class ConfigGroupModelPyTest(
|
||||
ConfigGroupModelTestCases,
|
||||
):
|
||||
pass
|
||||
|
@ -1071,6 +1071,7 @@ markers = [
|
||||
"centurion_models: Selects Centurion models",
|
||||
"functional: Selects all Functional tests.",
|
||||
"meta_models: Selects Meta models",
|
||||
"model_config_group: Selects Config Group tests.",
|
||||
"model_featureflag: Feature Flag Model",
|
||||
"model_gitgroup: Selects tests for model `git group`",
|
||||
"model_knowledge_base: Selects Knowledge base tests.",
|
||||
|
Reference in New Issue
Block a user