From c32c86a16f55b35ebb51b8c35f6151dc27b984d1 Mon Sep 17 00:00:00 2001 From: Fournet Enzo Date: Fri, 17 May 2024 22:54:50 +0200 Subject: [PATCH] Better test coverage --- test/app/hybridroutertest/tests.py | 31 ++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/test/app/hybridroutertest/tests.py b/test/app/hybridroutertest/tests.py index 211ac33..0228e91 100644 --- a/test/app/hybridroutertest/tests.py +++ b/test/app/hybridroutertest/tests.py @@ -4,6 +4,7 @@ from hybridrouter import HybridRouter from hybridroutertest.views import ServerConfigView, ClientModsView, ServerModsView, ServerConfigViewSet from django.urls import path, include +from unittest.mock import patch urlpatterns = [] @@ -97,9 +98,27 @@ def setUpTestData(cls): def test_intermediary_view_not_present(self): with self.assertRaises(NoReverseMatch): reverse('mods') - - # viewset_url = reverse('coucou-list') - # viewset_response = self.client.get(viewset_url) - # self.assertEqual(viewset_response.status_code, 200) - # attended_data = {'a': 'b'} - # self.assertEqual(viewset_response.data, attended_data) \ No newline at end of file + +class HybridRouterWithoutSpectacularWithIntermediaryViews(HybridRouterTestCaseWithIntermediaryViews): + @classmethod + @patch.dict('sys.modules', {'drf_spectacular.utils': None}) + def setUpTestData(cls): + try: + import importlib + hybridrouter_module = importlib.import_module('hybridrouter') + importlib.reload(hybridrouter_module) + super().setUpTestData() + except Exception as e: + cls.fail(f"HybridRouter failed when drf_spectacular is not installed: {e}") + +class HybridRouterWithoutSpectacularWithoutIntermediaryViews(HybridRouterTestCaseWithoutIntermediaryViews): + @classmethod + @patch.dict('sys.modules', {'drf_spectacular.utils': None}) + def setUpTestData(cls): + try: + import importlib + hybridrouter_module = importlib.import_module('hybridrouter') + importlib.reload(hybridrouter_module) + super().setUpTestData() + except Exception as e: + cls.fail(f"HybridRouter failed when drf_spectacular is not installed: {e}") \ No newline at end of file