Skip to content

Instantly share code, notes, and snippets.

@johnwayodi
Last active December 19, 2018 11:42
Show Gist options
  • Save johnwayodi/7f479f252451a601e4c67bfdcf3101db to your computer and use it in GitHub Desktop.
Save johnwayodi/7f479f252451a601e4c67bfdcf3101db to your computer and use it in GitHub Desktop.
Test that a User can Login with correct details ​
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)
@sharkdevs
Copy link

Hello wayodi,

Check grammar on your comments. Usershould should be users should

@Paulvitalis200
Copy link

Update your docstring at the beginning of test_user_login_valid_credentials method to be grammatically
correct

@johnwayodi
Copy link
Author

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

@johnwayodi
Copy link
Author

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