move tests

This commit is contained in:
Fabian Geisberger 2025-03-11 14:24:46 -04:00
parent a6eb2d0103
commit 4cbb17d2e3
2 changed files with 28 additions and 28 deletions

View File

@ -1396,34 +1396,6 @@ class DeviceTest(APIViewTestCases.APIViewTestCase):
self.assertHttpStatus(response, status.HTTP_200_OK)
self.assertEqual(response.data['content'], f'Config for device {device.name}')
def test_valid_local_context_data(self):
self.add_permissions('dcim.change_device')
device = Device.objects.first()
url = reverse('dcim-api:device-detail', kwargs={'pk': device.pk})
response = self.client.patch(url, {"local_context_data": None}, format='json', **self.header)
self.assertHttpStatus(response, status.HTTP_200_OK)
response = self.client.patch(url, {"local_context_data": {"foo": "bar"}}, format='json', **self.header)
self.assertHttpStatus(response, status.HTTP_200_OK)
def test_invalid_local_context_data(self):
self.add_permissions('dcim.change_device')
device = Device.objects.first()
url = reverse('dcim-api:device-detail', kwargs={'pk': device.pk})
response = self.client.patch(url, {"local_context_data": ""}, format='json', **self.header)
self.assertContains(response, 'JSON data must be in object form.', status_code=status.HTTP_400_BAD_REQUEST)
response = self.client.patch(url, {"local_context_data": 0}, format='json', **self.header)
self.assertContains(response, 'JSON data must be in object form.', status_code=status.HTTP_400_BAD_REQUEST)
response = self.client.patch(url, {"local_context_data": False}, format='json', **self.header)
self.assertContains(response, 'JSON data must be in object form.', status_code=status.HTTP_400_BAD_REQUEST)
response = self.client.patch(url, {"local_context_data": "foo"}, format='json', **self.header)
self.assertContains(response, 'JSON data must be in object form.', status_code=status.HTTP_400_BAD_REQUEST)
class ModuleTest(APIViewTestCases.APIViewTestCase):
model = Module

View File

@ -1,3 +1,4 @@
from django.forms import ValidationError
from django.test import TestCase
from core.models import ObjectType
@ -478,3 +479,30 @@ class ConfigContextTest(TestCase):
annotated_queryset = Device.objects.filter(name=device.name).annotate_config_context_data()
self.assertEqual(ConfigContext.objects.get_for_object(device).count(), 2)
self.assertEqual(device.get_config_context(), annotated_queryset[0].get_config_context())
def test_valid_local_context_data(self):
device = Device.objects.first()
device.local_context_data = None
device.clean()
device.local_context_data = {"foo": "bar"}
device.clean()
def test_invalid_local_context_data(self):
device = Device.objects.first()
device.local_context_data = ""
with self.assertRaises(ValidationError):
device.clean()
device.local_context_data = 0
with self.assertRaises(ValidationError):
device.clean()
device.local_context_data = False
with self.assertRaises(ValidationError):
device.clean()
device.local_context_data = 'foo'
with self.assertRaises(ValidationError):
device.clean()