-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RED] Add base code and test for Login feature.
- Loading branch information
1 parent
5c49d94
commit 58e1696
Showing
2 changed files
with
27 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,11 @@ | |
from django.urls import reverse | ||
import json | ||
|
||
REGISTER_LINK = reverse('authentication:register') | ||
LOGIN_LINK = reverse('authentication:login') | ||
|
||
class RegisterTest(TestCase): | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
|
@@ -13,7 +17,7 @@ def testRegisterValid(self): | |
"password":"pass1", | ||
"email":"[email protected]" | ||
} | ||
response = self.client.post(reverse('authentication:register'), json.dumps(data), content_type='application/json') | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertTrue(AppUser.objects.filter(username='user1').exists()) | ||
|
||
|
@@ -23,10 +27,9 @@ def testEmailFormatNotValid(self): | |
"password":"pass1", | ||
"email":"emailnotvalid" | ||
} | ||
response = self.client.post(reverse('authentication:register'), json.dumps(data), content_type='application/json') | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 400) | ||
resp_msg = json.loads(response.content.decode('utf-8'))['msg'] | ||
self.assertEqual(resp_msg,"Email format is wrong.") | ||
self.assertEqual(response.json()['msg'],"Email format is wrong.") | ||
self.assertFalse(AppUser.objects.filter(username='user1').exists()) | ||
|
||
def testEmptyInput(self): | ||
|
@@ -35,20 +38,28 @@ def testEmptyInput(self): | |
"password":"", | ||
"email":"" | ||
} | ||
response = self.client.post(reverse('authentication:register'), json.dumps(data), content_type='application/json') | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 400) | ||
resp_msg = json.loads(response.content.decode('utf-8'))['msg'] | ||
self.assertEqual(resp_msg,"Empty input! Make sure all the fields are filled.") | ||
self.assertEqual(response.json()['msg'],"Empty input! Make sure all the fields are filled.") | ||
|
||
def testUsernameIsAlreadyExist(self): | ||
data = { | ||
"username":"user1", | ||
"password":"pass1", | ||
"email":"[email protected]" | ||
} | ||
response = self.client.post(reverse('authentication:register'), json.dumps(data), content_type='application/json') | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 200) | ||
response = self.client.post(reverse('authentication:register'), json.dumps(data), content_type='application/json') | ||
response = self.client.post(REGISTER_LINK, json.dumps(data), content_type='application/json') | ||
self.assertEqual(response.status_code, 400) | ||
resp_msg = json.loads(response.content.decode('utf-8'))['msg'] | ||
self.assertEqual(resp_msg,"Username and/or email already taken!") | ||
self.assertEqual(response.json()['msg'],"Username and/or email already taken!") | ||
|
||
class LoginTest(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
self.user = AppUser.objects.create_user(email='[email protected]',username='testuser',password='test') | ||
|
||
def testLoginSuccessful(self): | ||
data = {'username': 'testuser', 'password': 'testpassword'} | ||
response = self.client.post(LOGIN_LINK, data=data) | ||
self.assertEqual(response.status_code, 200) |
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