mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 08:38:16 -06:00
Fix tests
This commit is contained in:
parent
36437c644d
commit
b4e8a3101a
@ -18,6 +18,7 @@ from extras.conditions import ConditionSet
|
|||||||
from extras.constants import *
|
from extras.constants import *
|
||||||
from extras.utils import image_upload
|
from extras.utils import image_upload
|
||||||
from netbox.config import get_config
|
from netbox.config import get_config
|
||||||
|
from netbox.events import get_event_type_choices
|
||||||
from netbox.models import ChangeLoggedModel
|
from netbox.models import ChangeLoggedModel
|
||||||
from netbox.models.features import (
|
from netbox.models.features import (
|
||||||
CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, SyncedDataMixin, TagsMixin,
|
CloningMixin, CustomFieldsMixin, CustomLinksMixin, ExportTemplatesMixin, SyncedDataMixin, TagsMixin,
|
||||||
@ -62,7 +63,7 @@ class EventRule(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin, ChangeLogged
|
|||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
event_types = ArrayField(
|
event_types = ArrayField(
|
||||||
base_field=models.CharField(max_length=50),
|
base_field=models.CharField(max_length=50, choices=get_event_type_choices),
|
||||||
help_text=_("The types of event which will trigger this rule.")
|
help_text=_("The types of event which will trigger this rule.")
|
||||||
)
|
)
|
||||||
enabled = models.BooleanField(
|
enabled = models.BooleanField(
|
||||||
|
@ -407,7 +407,7 @@ class EventRulesTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
cls.form_data = {
|
cls.form_data = {
|
||||||
'name': 'Event X',
|
'name': 'Event X',
|
||||||
'object_types': [site_type.pk],
|
'object_types': [site_type.pk],
|
||||||
'event_types': ','.join([OBJECT_UPDATED, OBJECT_DELETED]),
|
'event_types': [OBJECT_UPDATED, OBJECT_DELETED],
|
||||||
'conditions': None,
|
'conditions': None,
|
||||||
'action_type': 'webhook',
|
'action_type': 'webhook',
|
||||||
'action_object_type': webhook_ct.pk,
|
'action_object_type': webhook_ct.pk,
|
||||||
@ -418,7 +418,7 @@ class EventRulesTestCase(ViewTestCases.PrimaryObjectViewTestCase):
|
|||||||
|
|
||||||
cls.csv_data = (
|
cls.csv_data = (
|
||||||
f'name,object_types,event_types,action_type,action_object',
|
f'name,object_types,event_types,action_type,action_object',
|
||||||
f'Webhook 4,dcim.site,"{OBJECT_CREATED}",webhook,Webhook 1',
|
f'Webhook 4,dcim.site,"{OBJECT_CREATED},{OBJECT_UPDATED}",webhook,Webhook 1',
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.csv_update_data = (
|
cls.csv_update_data = (
|
||||||
|
@ -137,7 +137,10 @@ class ModelTestCase(TestCase):
|
|||||||
|
|
||||||
# Convert ArrayFields to CSV strings
|
# Convert ArrayFields to CSV strings
|
||||||
if type(field) is ArrayField:
|
if type(field) is ArrayField:
|
||||||
if type(field.base_field) is ArrayField:
|
if getattr(field.base_field, 'choices', None):
|
||||||
|
# Values for fields with pre-defined choices can be returned as lists
|
||||||
|
model_dict[key] = value
|
||||||
|
elif type(field.base_field) is ArrayField:
|
||||||
# Handle nested arrays (e.g. choice sets)
|
# Handle nested arrays (e.g. choice sets)
|
||||||
model_dict[key] = '\n'.join([f'{k},{v}' for k, v in value])
|
model_dict[key] = '\n'.join([f'{k},{v}' for k, v in value])
|
||||||
elif issubclass(type(field.base_field), RangeField):
|
elif issubclass(type(field.base_field), RangeField):
|
||||||
|
Loading…
Reference in New Issue
Block a user