Merge branch '566-custom-rooturl-in-tests' into 'master'
Support custom ROOT_URLCONF in tests - fixes #566 Closes #566 See merge request mayan-edms/mayan-edms!37
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
from __future__ import absolute_import, unicode_literals
|
from __future__ import absolute_import, unicode_literals
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
@@ -42,15 +44,15 @@ class GenericViewTestCase(BaseTestCase):
|
|||||||
self.has_test_view = False
|
self.has_test_view = False
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
from mayan.urls import urlpatterns
|
urlconf = importlib.import_module(settings.ROOT_URLCONF)
|
||||||
|
|
||||||
self.client.logout()
|
self.client.logout()
|
||||||
if self.has_test_view:
|
if self.has_test_view:
|
||||||
urlpatterns.pop(0)
|
urlconf.urlpatterns.pop(0)
|
||||||
super(GenericViewTestCase, self).tearDown()
|
super(GenericViewTestCase, self).tearDown()
|
||||||
|
|
||||||
def add_test_view(self, test_object):
|
def add_test_view(self, test_object):
|
||||||
from mayan.urls import urlpatterns
|
urlconf = importlib.import_module(settings.ROOT_URLCONF)
|
||||||
|
|
||||||
def test_view(request):
|
def test_view(request):
|
||||||
template = Template('{{ object }}')
|
template = Template('{{ object }}')
|
||||||
@@ -59,7 +61,7 @@ class GenericViewTestCase(BaseTestCase):
|
|||||||
)
|
)
|
||||||
return HttpResponse(template.render(context=context))
|
return HttpResponse(template.render(context=context))
|
||||||
|
|
||||||
urlpatterns.insert(0, url(TEST_VIEW_URL, test_view, name=TEST_VIEW_NAME))
|
urlconf.urlpatterns.insert(0, url(TEST_VIEW_URL, test_view, name=TEST_VIEW_NAME))
|
||||||
clear_url_caches()
|
clear_url_caches()
|
||||||
self.has_test_view = True
|
self.has_test_view = True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user