Skip to content

Instantly share code, notes, and snippets.

@kaygorodov
Last active November 25, 2019 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaygorodov/8792346 to your computer and use it in GitHub Desktop.
Save kaygorodov/8792346 to your computer and use it in GitHub Desktop.
Django-Rest-Framework testing views that use sessions
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
class MyAPICase(APITestCase):
def setUp(self):
user = User.objects.create_user('test_user',
'test@email.com', '12345')
self.client.force_authenticate(user=user)
self.client.login(username='test_user', password='12345')
session = self.client.session
session['some_session_key'] = 'some_session_value'
session.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment