refactor(config_management): Add ConfigGroupHost Model Tests

ref: #804 #793
This commit is contained in:
2025-06-07 13:54:45 +09:30
parent 39208edf93
commit 71108f6089
4 changed files with 105 additions and 3 deletions

View File

@ -0,0 +1,39 @@
# Generated by Django 5.1.9 on 2025-06-07 04:11
import config_management.models.groups
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("config_management", "0013_alter_configgroupsoftware_action_and_more"),
("itam", "0014_remove_device_is_global_remove_device_slug_and_more"),
]
operations = [
migrations.AlterField(
model_name="configgrouphosts",
name="group",
field=models.ForeignKey(
help_text="Group that this host is part of",
on_delete=django.db.models.deletion.PROTECT,
to="config_management.configgroups",
verbose_name="Group",
),
),
migrations.AlterField(
model_name="configgrouphosts",
name="host",
field=models.ForeignKey(
help_text="Host that will be apart of this config group",
on_delete=django.db.models.deletion.PROTECT,
to="itam.device",
validators=[
config_management.models.groups.ConfigGroupHosts.validate_host_no_parent_group
],
verbose_name="Host",
),
),
]

View File

@ -352,9 +352,9 @@ class ConfigGroupHosts(
host = models.ForeignKey(
Device,
blank= False,
blank = False,
help_text = 'Host that will be apart of this config group',
on_delete=models.CASCADE,
on_delete = models.PROTECT,
null = False,
validators = [ validate_host_no_parent_group ],
verbose_name = 'Host',
@ -365,7 +365,7 @@ class ConfigGroupHosts(
ConfigGroups,
blank= False,
help_text = 'Group that this host is part of',
on_delete=models.CASCADE,
on_delete = models.PROTECT,
null = False,
verbose_name = 'Group',
)

View File

@ -0,0 +1,62 @@
import pytest
from django.db import models
from core.tests.unit.centurion_abstract.test_unit_centurion_abstract_model import (
CenturionAbstractModelInheritedCases
)
@pytest.mark.model_config_group_hosts
class ConfigGroupSoftwareModelTestCases(
CenturionAbstractModelInheritedCases
):
@property
def parameterized_class_attributes(self):
return {}
parameterized_model_fields = {
'host': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': False,
'unique': False,
},
'group': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.ForeignKey,
'null': False,
'unique': False,
},
'modified': {
'blank': False,
'default': models.fields.NOT_PROVIDED,
'field_type': models.DateTimeField,
'null': False,
'unique': False,
},
}
class ConfigGroupSoftwareModelInheritedCases(
ConfigGroupSoftwareModelTestCases,
):
pass
class ConfigGroupSoftwareModelPyTest(
ConfigGroupSoftwareModelTestCases,
):
pass

View File

@ -1072,6 +1072,7 @@ markers = [
"functional: Selects all Functional tests.",
"meta_models: Selects Meta models",
"model_config_group: Selects Config Group tests.",
"model_config_group_hosts: Selects Config Group Hosts tests.",
"model_config_group_software: Selects Config Group Software tests.",
"model_featureflag: Feature Flag Model",
"model_gitgroup: Selects tests for model `git group`",