Skip to content

Commit

Permalink
all test done, gogod coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
enzofrnt committed May 18, 2024
1 parent 0c7fa32 commit 87ff78c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
2 changes: 1 addition & 1 deletion hybridrouter/hybridrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DRF_SPECTACULAR = True
except ImportError:
DRF_SPECTACULAR = False

def conditionally_extend_schema(exclude=True):
def decorator(view_func):
if DRF_SPECTACULAR:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import unittest
import sys
import importlib
import os

from django import setup
from django.conf import settings
if not settings.configured:

if settings.configured is False:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
setup()
else:
setup()

from unittest.mock import patch
from hybridrouter import HybridRouter
from django.test import TestCase, override_settings
from django.urls import reverse, NoReverseMatch
from rest_framework.test import APIClient
from hybridroutertest.views import ServerConfigView, ClientModsView, ServerModsView, ServerConfigViewSet
from django.urls import path, include
from unittest.mock import patch
from django.urls import path, include, reverse, NoReverseMatch

urlpatterns = []

Expand Down Expand Up @@ -69,7 +72,7 @@ def test_router_regsiter_view_deprecated(self):
with self.assertRaises(NotImplementedError):
self.router.register('prefix', 'viewset', 'basename')

@override_settings(ROOT_URLCONF='hybridroutertest.tests.testo')
@override_settings(ROOT_URLCONF='hybridroutertest.tests')
class HybridRouterTestCaseWithIntermediaryViews(CommonHybridRouterTests, HybridRouterTests):

def setUp(self, router=None):
Expand Down Expand Up @@ -114,7 +117,7 @@ def test_api_root_view(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, attended_data)

@override_settings(ROOT_URLCONF='hybridroutertest.tests.testo')
@override_settings(ROOT_URLCONF='hybridroutertest.tests')
class HybridRouterTestCaseWithoutIntermediaryViews(CommonHybridRouterTests, HybridRouterTests):

def setUp(self, router=None):
Expand Down Expand Up @@ -153,3 +156,32 @@ def test_api_root_view(self):





class TestHybridRouterWithoutSpectacular(unittest.TestCase):

def setUp(self):
super().setUp()
modules_to_remove = [
'hybridrouter', 'hybridrouter.hybridrouter', 'drf_spectacular', 'drf_spectacular.utils'
]
for module in modules_to_remove:
if module in sys.modules:
del sys.modules[module]

@patch.dict('sys.modules', {'drf_spectacular': None})
def test_import_error(self):
from hybridrouter import hybridrouter
importlib.reload(hybridrouter)
self.assertTrue(hasattr(hybridrouter, 'DRF_SPECTACULAR'))
self.assertFalse(getattr(hybridrouter, 'DRF_SPECTACULAR'))


class HybridRouterTestCaseWithIntermediaryViewsWithoutSpectacular(TestHybridRouterWithoutSpectacular, HybridRouterTestCaseWithIntermediaryViews):
def setUp(cls):
super().setUp()

class HybridRouterTestCaseWithoutIntermediaryViewsWithoutSpectacular(TestHybridRouterWithoutSpectacular, HybridRouterTestCaseWithoutIntermediaryViews):
def setUp(cls):
super().setUp()

Empty file.
36 changes: 0 additions & 36 deletions test/app/hybridroutertest/tests/testi.py

This file was deleted.

0 comments on commit 87ff78c

Please sign in to comment.