-
-
Save mekhami/d996f2a53c470085cab9fc85f2ed1231 to your computer and use it in GitHub Desktop.
Example TestCase for unit test Django middlewares
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.test import RequestFactory, TestCase | |
from myapp.middleware import MyMiddleware | |
class MyMiddlewareTestCase(TestCase): | |
def setUp(self): | |
super(MyMiddlewareTestCase, self).setUp() | |
self.factory = RequestFactory() | |
self.mm = MyMiddlewareTest() | |
self.view = lambda x: None | |
self.request = self.factory.get('/') | |
def test_stuff_get_access_denied(self): | |
response = self.mm.process_view(self.request, self.view, [], {}) | |
self.assertEqual(response.status_code, 403) | |
def test_stuff_with_user(self): | |
# code for setting up and login a user | |
response = self.mm.process_view(self.request, self.view, [], {}) | |
self.assertEqual(response.status_code, 200) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment