Created
September 19, 2018 12:29
-
-
Save imireallan/cf8aac3c051a017d61bbfbc16450bdb4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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) | |
Neat code!
Your tests are straight to the point. The unsuccessful scenario would be better with more tests. Like:
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
Good work