-
-
Save johnwayodi/7f479f252451a601e4c67bfdcf3101db to your computer and use it in GitHub Desktop.
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) |
Make sure to import the
TestCase
module from django:from django.test import TestCase
Thanks for noticing that, I'll make sure to add that
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
Hello wayodi,
Check grammar on your comments. Usershould
should be users should
Update your docstring at the beginning of test_user_login_valid_credentials
method to be grammatically
correct
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.
Make sure to import the
TestCase
module from django: