mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-18 05:28:16 -06:00
Move test for invalid choices to CustomFieldChoiceSetTest
This commit is contained in:
parent
bb72af864b
commit
73ab0425e8
@ -252,6 +252,23 @@ class CustomFieldChoiceSetTest(APIViewTestCases.APIViewTestCase):
|
|||||||
)
|
)
|
||||||
CustomFieldChoiceSet.objects.bulk_create(choice_sets)
|
CustomFieldChoiceSet.objects.bulk_create(choice_sets)
|
||||||
|
|
||||||
|
def test_invalid_choice_items(self):
|
||||||
|
"""
|
||||||
|
Attempting to define each choice as a single-item list should return a 400 error.
|
||||||
|
"""
|
||||||
|
self.add_permissions('extras.add_customfieldchoiceset')
|
||||||
|
data = {
|
||||||
|
"name": "test",
|
||||||
|
"extra_choices": [
|
||||||
|
["choice1"],
|
||||||
|
["choice2"],
|
||||||
|
["choice3"],
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
response = self.client.post(self._get_list_url(), data, format='json', **self.header)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
|
||||||
class CustomLinkTest(APIViewTestCases.APIViewTestCase):
|
class CustomLinkTest(APIViewTestCases.APIViewTestCase):
|
||||||
model = CustomLink
|
model = CustomLink
|
||||||
@ -897,56 +914,3 @@ class ContentTypeTest(APITestCase):
|
|||||||
|
|
||||||
url = reverse('extras-api:contenttype-detail', kwargs={'pk': contenttype.pk})
|
url = reverse('extras-api:contenttype-detail', kwargs={'pk': contenttype.pk})
|
||||||
self.assertHttpStatus(self.client.get(url, **self.header), status.HTTP_200_OK)
|
self.assertHttpStatus(self.client.get(url, **self.header), status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class CustomFieldChoiceSetsEndpointTest(test.APITestCase):
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.super_user = User.objects.create_user(username='testuser', is_staff=True, is_superuser=True)
|
|
||||||
self.token = Token.objects.create(user=self.super_user)
|
|
||||||
self.header = {'HTTP_AUTHORIZATION': f'Token {self.token.key}'}
|
|
||||||
self.url = '/api/extras/custom-field-choice-sets/'
|
|
||||||
|
|
||||||
def test_extra_choices_only_one_choice_element_return_400(self):
|
|
||||||
payload = {
|
|
||||||
"name": "test",
|
|
||||||
"extra_choices": [["choice1"]]
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.client.post(self.url, payload, format='json', **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
||||||
def test_extra_choices_two_wrong_choice_elements_return_400(self):
|
|
||||||
payload = {
|
|
||||||
"name": "test",
|
|
||||||
"extra_choices": [["choice1"], ["choice2"]]
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.client.post(self.url, payload, format='json', **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
||||||
def test_extra_choices_one_is_wrong_other_correct_choice_elements_return_400(self):
|
|
||||||
payload = {
|
|
||||||
"name": "test",
|
|
||||||
"extra_choices": [["1A", "choice1"], ["choice2"]]
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.client.post(self.url, payload, format='json', **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 400)
|
|
||||||
|
|
||||||
def test_extra_choices_correct_choices_return_201(self):
|
|
||||||
payload = {
|
|
||||||
'name': 'Choice Set',
|
|
||||||
'extra_choices': [
|
|
||||||
['4A', 'Choice 1'],
|
|
||||||
['4B', 'Choice 2'],
|
|
||||||
['4C', 'Choice 3'],
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
response = self.client.post(self.url, payload, format='json', **self.header)
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 201)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user