Skip to content

Instantly share code, notes, and snippets.

@doismellburning
Last active January 4, 2017 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doismellburning/3a7d78590a2148f1a85bdcf1bd5acb35 to your computer and use it in GitHub Desktop.
Save doismellburning/3a7d78590a2148f1a85bdcf1bd5acb35 to your computer and use it in GitHub Desktop.
Django TestClient sessions - what am I missing...?
======================================================================
FAIL: test_clear_token_with_token (article.tests.test_views.ArticleViewsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/root/article/tests/test_views.py", line 92, in test_clear_token_with_token
self.assertIsNotNone(self.client.session.get('token'))
AssertionError: unexpectedly None
----------------------------------------------------------------------
def test_clear_token_with_token(self):
url = reverse("article:clear_token")
# https://docs.djangoproject.com/en/1.10/topics/testing/tools/#django.test.Client.session
# "To modify the session and then save it, it must be stored in a variable first
# (because a new SessionStore is created every time this property is accessed):"
session = self.client.session
session['token'] = "loremipsum"
session.save()
self.assertIsNotNone(self.client.session.get('token'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment