mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 10:58:37 -06:00
move tests
This commit is contained in:
parent
a6eb2d0103
commit
4cbb17d2e3
@ -1396,34 +1396,6 @@ class DeviceTest(APIViewTestCases.APIViewTestCase):
|
|||||||
self.assertHttpStatus(response, status.HTTP_200_OK)
|
self.assertHttpStatus(response, status.HTTP_200_OK)
|
||||||
self.assertEqual(response.data['content'], f'Config for device {device.name}')
|
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):
|
class ModuleTest(APIViewTestCases.APIViewTestCase):
|
||||||
model = Module
|
model = Module
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.forms import ValidationError
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from core.models import ObjectType
|
from core.models import ObjectType
|
||||||
@ -478,3 +479,30 @@ class ConfigContextTest(TestCase):
|
|||||||
annotated_queryset = Device.objects.filter(name=device.name).annotate_config_context_data()
|
annotated_queryset = Device.objects.filter(name=device.name).annotate_config_context_data()
|
||||||
self.assertEqual(ConfigContext.objects.get_for_object(device).count(), 2)
|
self.assertEqual(ConfigContext.objects.get_for_object(device).count(), 2)
|
||||||
self.assertEqual(device.get_config_context(), annotated_queryset[0].get_config_context())
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user