Last active
December 19, 2018 11:42
-
-
Save johnwayodi/7f479f252451a601e4c67bfdcf3101db to your computer and use it in GitHub Desktop.
Test that a User can Login with correct details
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 TestCase | |
from rest_framework.test import APIClient | |
from rest_framework import status | |
from django.core.urlresolvers import reverse | |
class LoginTestCase(TestCase): | |
"""Test suite for the api login views.""" | |
def setUp(self): | |
"""Set up test client""" | |
self.client = APIClient() | |
self.user_data = {'name': 'JohnDoe', 'password': 'johnDoe2341'} | |
def test_user_login_valid_credentials(self): | |
"""User should be able to login when valid | |
credentials are provided.""" | |
# create the user | |
self.response = self.client.post(reverse('register'), | |
self.user_data, format="json") | |
self.assertEqual(self.response.status_code, | |
status.HTTP_201_CREATED) | |
# login the user | |
self.response = self.client.post(reverse('login'), | |
self.user_data, | |
format="json") | |
self.assertEqual(self.response.status_code, status.HTTP_200_OK) |
Hi John,
I have noticed a typo that will definately give you a bug.
self.user_data = {'name': 'JohnDoe', 'password': 'johnDoe2341}
missing a single quotation on password.Regards
Steven Ennis
Thanks for noticing that. lemme correct that
PaulStar200, sharkdevs thanks for the feedback, I'll correct that.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update your docstring at the beginning of
test_user_login_valid_credentials
method to be grammaticallycorrect