Skip to content

Commit

Permalink
Clean up bulk import & extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jan 3, 2025
1 parent 750e325 commit 1d533c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions netbox/circuits/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,15 @@ class Meta:


class CircuitGroupAssignmentImportForm(NetBoxModelImportForm):
member_type = CSVContentTypeField(
queryset=ContentType.objects.filter(CIRCUIT_GROUP_ASSIGNMENT_MEMBER_MODELS),
label=_('Circuit type (app & model)')
)
priority = CSVChoiceField(
label=_('Priority'),
choices=CircuitPriorityChoices,
required=False
)

class Meta:
model = CircuitGroupAssignment
Expand Down
4 changes: 3 additions & 1 deletion netbox/circuits/models/circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ class CircuitGroupAssignment(CustomFieldsMixin, ExportTemplatesMixin, TagsMixin,
on_delete=models.PROTECT,
related_name='+'
)
member_id = models.PositiveBigIntegerField()
member_id = models.PositiveBigIntegerField(
verbose_name=_('member ID')
)
member = GenericForeignKey(
ct_field='member_type',
fk_field='member_id'
Expand Down
15 changes: 15 additions & 0 deletions netbox/circuits/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ class CircuitGroupAssignmentTestCase(
ViewTestCases.DeleteObjectViewTestCase,
ViewTestCases.ListObjectsViewTestCase,
ViewTestCases.BulkEditObjectsViewTestCase,
ViewTestCases.BulkImportObjectsViewTestCase,
ViewTestCases.BulkDeleteObjectsViewTestCase
):
model = CircuitGroupAssignment
Expand Down Expand Up @@ -523,6 +524,20 @@ def setUpTestData(cls):
'tags': [t.pk for t in tags],
}

cls.csv_data = (
"member_type,member_id,group,priority",
f"circuits.circuit,{circuits[0].pk},{circuit_groups[3].pk},primary",
f"circuits.circuit,{circuits[1].pk},{circuit_groups[3].pk},secondary",
f"circuits.circuit,{circuits[2].pk},{circuit_groups[3].pk},tertiary",
)

cls.csv_update_data = (
"id,priority",
f"{assignments[0].pk},inactive",
f"{assignments[1].pk},inactive",
f"{assignments[2].pk},inactive",
)

cls.bulk_edit_data = {
'priority': CircuitPriorityChoices.PRIORITY_INACTIVE,
}
Expand Down

0 comments on commit 1d533c4

Please sign in to comment.