Skip to content

Instantly share code, notes, and snippets.

@imireallan
Created September 19, 2018 12:29
Show Gist options
  • Save imireallan/cf8aac3c051a017d61bbfbc16450bdb4 to your computer and use it in GitHub Desktop.
Save imireallan/cf8aac3c051a017d61bbfbc16450bdb4 to your computer and use it in GitHub Desktop.
from django.test import TestCase
from rest_framework import status
from rest_framework.test import APIClient
class LoginTestCase(TestCase):
def setUp(self):
self.client = APIClient()
self.user = {
'username':'allanimire',
'password':'password123'
}
self.non_user = {
'username':'',
'password':'password123'
}
def test_successfull_login(self):
resp = self.client.post('api/users', self.user, format='json')
self.assertIn(b'User successfully logged in', resp.data)
def test_unsucessfull_login(self):
resp = self.client.post('api/users', self.non_user, format='json')
self.assertTrue(resp.status_code, status.HTTP_400_BAD_REQUEST)
@mutaimwiti
Copy link

Your tests are straight to the point. The unsuccessful scenario would be better with more tests. Like:

@mutaimwiti
Copy link

It is good that the tests are straight to the point. As @gitaumoses4 mentioned, test_unsucessful should have more scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment