|
@@ -613,6 +613,66 @@ class GraphQLAPITestCase(APITestCase):
|
|
|
msg=f'Expected batched tag prefetch, got {tag_queries} tag queries for 10 devices',
|
|
msg=f'Expected batched tag prefetch, got {tag_queries} tag queries for 10 devices',
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ def test_graphql_device_list_tags_pagination(self):
|
|
|
|
|
+ """
|
|
|
|
|
+ Pagination can be applied to a prefetched list field (tags).
|
|
|
|
|
+ """
|
|
|
|
|
+ self.add_permissions('dcim.view_device', 'extras.view_tag')
|
|
|
|
|
+
|
|
|
|
|
+ manufacturer = Manufacturer.objects.create(name='Pagination Manufacturer', slug='pagination-manufacturer')
|
|
|
|
|
+ device_type = DeviceType.objects.create(
|
|
|
|
|
+ manufacturer=manufacturer,
|
|
|
|
|
+ model='Pagination Model',
|
|
|
|
|
+ slug='pagination-model',
|
|
|
|
|
+ )
|
|
|
|
|
+ device_role = DeviceRole.objects.create(name='Pagination Role', slug='pagination-role')
|
|
|
|
|
+ device = Device.objects.create(
|
|
|
|
|
+ name='Pagination Device',
|
|
|
|
|
+ device_type=device_type,
|
|
|
|
|
+ role=device_role,
|
|
|
|
|
+ site=Site.objects.first(),
|
|
|
|
|
+ )
|
|
|
|
|
+ device.tags.set([
|
|
|
|
|
+ Tag.objects.create(name=f'Pagination Tag {index}', slug=f'pagination-tag-{index}')
|
|
|
|
|
+ for index in range(5)
|
|
|
|
|
+ ])
|
|
|
|
|
+
|
|
|
|
|
+ query = """
|
|
|
|
|
+ {
|
|
|
|
|
+ device_list(filters: {role: {slug: {exact: "pagination-role"}}}) {
|
|
|
|
|
+ tags(pagination: {offset: 1, limit: 2}) {
|
|
|
|
|
+ slug
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ """
|
|
|
|
|
+ url = reverse('graphql')
|
|
|
|
|
+ response = self.client.post(url, data={'query': query}, format='json', **self.header)
|
|
|
|
|
+ self.assertHttpStatus(response, status.HTTP_200_OK)
|
|
|
|
|
+ data = json.loads(response.content)
|
|
|
|
|
+ self.assertNotIn('errors', data)
|
|
|
|
|
+ self.assertEqual(
|
|
|
|
|
+ [tag['slug'] for tag in data['data']['device_list'][0]['tags']],
|
|
|
|
|
+ ['pagination-tag-1', 'pagination-tag-2'],
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # MAX_PAGE_SIZE is enforced when no pagination is specified
|
|
|
|
|
+ query = """
|
|
|
|
|
+ {
|
|
|
|
|
+ device_list(filters: {role: {slug: {exact: "pagination-role"}}}) {
|
|
|
|
|
+ tags {
|
|
|
|
|
+ slug
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ """
|
|
|
|
|
+ with override_settings(MAX_PAGE_SIZE=3):
|
|
|
|
|
+ response = self.client.post(url, data={'query': query}, format='json', **self.header)
|
|
|
|
|
+ self.assertHttpStatus(response, status.HTTP_200_OK)
|
|
|
|
|
+ data = json.loads(response.content)
|
|
|
|
|
+ self.assertNotIn('errors', data)
|
|
|
|
|
+ self.assertEqual(len(data['data']['device_list'][0]['tags']), 3)
|
|
|
|
|
+
|
|
|
def test_graphql_ip_address_list_assigned_object(self):
|
|
def test_graphql_ip_address_list_assigned_object(self):
|
|
|
"""
|
|
"""
|
|
|
Requesting assigned_object should batch prefetch related objects.
|
|
Requesting assigned_object should batch prefetch related objects.
|