Created
March 29, 2023 09:12
-
-
Save AndreasDickow/318eef68460dfa8fdf41272c5cbebff0 to your computer and use it in GitHub Desktop.
Django Unit Test Templatetags: how to circumvent the WSGIRequest has no attribute 'request' Problem
This file contains hidden or 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
class CustomTagTestCase(BaseTestCase): | |
"""_summary_: includes tests of custom templatetags from templatetags/custom_tags.py | |
Args: | |
BaseTestCase (_type_): _description_ | |
""" | |
def test_count_session_time(self): | |
"""_summary_: test clean_text | |
Args: | |
self (_type_): _description_ | |
""" | |
request = RequestFactory().get('/') | |
client = Client() | |
client.force_login(user=self.user) | |
middleware = SessionMiddleware(client.get) | |
middleware.process_request(request) | |
request.session.save() | |
request.user = self.user | |
context = RequestContext(request) | |
time = count_session_time(context) | |
self.assertEqual(time, '60') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment