From 567940ebd78ebc99f0a5676e57b4f760d0d06db9 Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 24 Jul 2026 17:55:07 -0700 Subject: [PATCH] add tests --- netbox/netbox/tests/test_graphql.py | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/netbox/netbox/tests/test_graphql.py b/netbox/netbox/tests/test_graphql.py index 2874354ef..472ac43cf 100644 --- a/netbox/netbox/tests/test_graphql.py +++ b/netbox/netbox/tests/test_graphql.py @@ -352,6 +352,41 @@ class GraphQLAPITestCase(APITestCase): self.assertEqual(len(data['data']['rack_reservation_list']), 1) self.assertEqual(data['data']['rack_reservation_list'][0]['units'], [1, 2]) + def test_graphql_array_lookups(self): + """ + The ``contains``, ``contained_by``, and ``overlap`` array lookups share their name with the + corresponding ORM transform. Verify they still resolve after #22766 replaced the auto-generated + filter fields with a manual ``filter()`` method. + """ + self.add_permissions('dcim.view_rackreservation') + url = reverse('graphql') + + site = Site.objects.first() + rack = Rack.objects.create(name='Array Lookup Rack', site=site) + RackReservation.objects.create(rack=rack, units=[1, 2], user=self.user, description='Low units') + RackReservation.objects.create(rack=rack, units=[3, 4, 5], user=self.user, description='High units') + + def run(lookup): + query = f""" + {{ + rack_reservation_list(filters: {{units: {lookup}}}) {{ + id units + }} + }} + """ + 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) + return [r['units'] for r in data['data']['rack_reservation_list']] + + # contains: arrays that include all of the given elements + self.assertEqual(run('{contains: [1]}'), [[1, 2]]) + # contained_by: arrays whose elements all fall within the given set + self.assertEqual(run('{contained_by: [1, 2, 3]}'), [[1, 2]]) + # overlap: arrays sharing at least one element with the given set + self.assertCountEqual(run('{overlap: [2, 3]}'), [[1, 2], [3, 4, 5]]) + def test_graphql_tableconfig_object_type_exposes_id(self): """TableConfigType.object_type must expose ContentType fields (e.g. id).""" self.add_permissions('extras.view_tableconfig')