Skip to content

Instantly share code, notes, and snippets.

@AndreasDickow
Created March 29, 2023 09:12
Show Gist options
  • Save AndreasDickow/318eef68460dfa8fdf41272c5cbebff0 to your computer and use it in GitHub Desktop.
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
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