Django unittest's: How to set up temporary browsing with a temporary url for unittest's

I created a couple of intermediate classes and I want to test them against some real representations. Since my application does not include any views or url conf, I was wondering if there is a way to temporarily create views and configure URLs only for testing (similar to the test database) within the Django test database. In the end, I would like to use a test client to check these temporary views for errors that arise from middleware. I did not find a solution for this in the docs.

I know that I can create a test view in my application (in views.py) and point it to ROOT_URLCONF, but I do not want to force the user to do this when using my application and want to test my middleware classes.

Any ideas?

Thanks.

+7
source share
1 answer

Yes, it is possible if you use django.test.TestCase . The following are the documentation for configuring the URL for a specific test case: https://docs.djangoproject.com/en/1.8/topics/testing/tools/#urlconf-configuration

When I did this before, I usually break my test suite as a sub-application (no models):

 tests __init__.py urls.py views.py base.py 

Then in the test case you should set:

 class MiddlewareTestCase(TestCase): urls = 'appname.tests.urls' 
+7
source

All Articles