From d3bb22931b3f07ec9ded381205bbe02eebad2037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Szulc?= Date: Mon, 18 Nov 2024 12:34:56 +0100 Subject: [PATCH] Fix renderer classes ordering --- src/ralph/assets/tests/test_api.py | 4 ++-- src/ralph/lib/api/utils.py | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/ralph/assets/tests/test_api.py b/src/ralph/assets/tests/test_api.py index b30b507be1..9420ba5f7a 100644 --- a/src/ralph/assets/tests/test_api.py +++ b/src/ralph/assets/tests/test_api.py @@ -958,8 +958,8 @@ def test_get_dc_hosts_list(self): VirtualServerFullFactory.create_batch(20, parent=dc_assets[0]) CloudHostFullFactory.create_batch(20, hypervisor=dc_assets[0]) url = reverse('dchost-list') + "?limit=100" - with self.assertNumQueries(31): - response = self.client.get(url, format='json') + with self.assertQueriesMoreOrLess(30, plus_minus=1): + response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data['count'], 63) diff --git a/src/ralph/lib/api/utils.py b/src/ralph/lib/api/utils.py index 0bde48d5f3..fa7c652d88 100644 --- a/src/ralph/lib/api/utils.py +++ b/src/ralph/lib/api/utils.py @@ -120,7 +120,10 @@ def render_form_for_serializer(self, serializer): def renderer_classes_without_form(renderer_classes): - return [OnlyRawBrowsableAPIRenderer] + [ - rc for rc in renderer_classes - if not isinstance(rc(), BrowsableAPIRenderer) - ] + def _gen(): + for rc in renderer_classes: + if not isinstance(rc(), BrowsableAPIRenderer): + yield rc + else: + yield OnlyRawBrowsableAPIRenderer + return [rc for rc in _gen()]