Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion netbox/dcim/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from django.test import override_settings
from django.test import override_settings, tag
from django.urls import reverse
from django.utils.translation import gettext as _
from rest_framework import status
Expand Down Expand Up @@ -1904,6 +1904,27 @@ def setUpTestData(cls):
},
]

@tag('regression') # Issue #18991
def test_front_port_paths(self):
device = Device.objects.first()
rear_port = RearPort.objects.create(
device=device, name='Rear Port 10', type=PortTypeChoices.TYPE_8P8C
)
interface1 = Interface.objects.create(device=device, name='Interface 1')
front_port = FrontPort.objects.create(
device=device,
name='Rear Port 10',
type=PortTypeChoices.TYPE_8P8C,
rear_port=rear_port,
)
Cable.objects.create(a_terminations=[interface1], b_terminations=[front_port])

self.add_permissions(f'dcim.view_{self.model._meta.model_name}')
url = reverse(f'dcim-api:{self.model._meta.model_name}-paths', kwargs={'pk': front_port.pk})
response = self.client.get(url, **self.header)

self.assertHttpStatus(response, status.HTTP_200_OK)


class RearPortTest(APIViewTestCases.APIViewTestCase):
model = RearPort
Expand Down Expand Up @@ -1947,6 +1968,23 @@ def setUpTestData(cls):
},
]

@tag('regression') # Issue #18991
def test_rear_port_paths(self):
device = Device.objects.first()
interface1 = Interface.objects.create(device=device, name='Interface 1')
rear_port = RearPort.objects.create(
device=device,
name='Rear Port 10',
type=PortTypeChoices.TYPE_8P8C,
)
Cable.objects.create(a_terminations=[interface1], b_terminations=[rear_port])

self.add_permissions(f'dcim.view_{self.model._meta.model_name}')
url = reverse(f'dcim-api:{self.model._meta.model_name}-paths', kwargs={'pk': rear_port.pk})
response = self.client.get(url, **self.header)

self.assertHttpStatus(response, status.HTTP_200_OK)


class ModuleBayTest(APIViewTestCases.APIViewTestCase):
model = ModuleBay
Expand Down
4 changes: 2 additions & 2 deletions netbox/utilities/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ class GenericArrayForeignKey(FieldCacheMixin, models.Field):
Provide a generic many-to-many relation through an 2d array field
"""

many_to_many = True
many_to_many = False
many_to_one = False
one_to_many = False
one_to_many = True
one_to_one = False

def __init__(self, field, for_concrete_model=True):
Expand Down