-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests and update requirements for Postgres binary
- Loading branch information
1 parent
81ad35d
commit 372f52d
Showing
2 changed files
with
81 additions
and
2 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 |
---|---|---|
@@ -1,3 +1,82 @@ | ||
from accounts.models import User | ||
from django.test import Client | ||
from django.test import RequestFactory | ||
from django.test import TestCase | ||
from django.urls import reverse | ||
|
||
# Create your tests here. | ||
|
||
class AccountsTestCase(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
self.factory = RequestFactory() | ||
self.user = User.objects.create( | ||
first_name="Test", | ||
last_name="User", | ||
email="[email protected]", | ||
phone_no="9876543210", | ||
gender="M", | ||
password="testuser@password", | ||
) | ||
self.signin_path = reverse("accounts_signin") | ||
self.signup_path = reverse("accounts_signup") | ||
self.signout_path = reverse("accounts_signout") | ||
self.index_path = reverse("index") | ||
|
||
def test_successful_signup(self): | ||
form_data = { | ||
"first_name": "First 1", | ||
"last_name": "Last 1", | ||
"email": "[email protected]", | ||
"phone_no": "0000000000", | ||
"gender": "M", | ||
"password1": "user1@password", | ||
"password2": "user1@password", | ||
} | ||
|
||
response = self.client.post(self.signup_path, form_data, follow=True) | ||
messages = list(response.context.get("messages")) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(messages), 1) | ||
self.assertEqual( | ||
str(messages[0]), "You have been successfully registered. Please sign in!" | ||
) | ||
|
||
self.assertRedirects(response, self.signin_path) | ||
|
||
def test_unsuccessful_signup(self): | ||
form_data = { | ||
"first_name": "First 1", | ||
"last_name": "Last 1", | ||
"email": "[email protected]", | ||
"phone_no": "0000000000", | ||
"gender": "M", | ||
"password1": "user1@password", | ||
"password2": "user1@password", | ||
} | ||
|
||
response = self.client.post(self.signup_path, form_data, follow=True) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertIsNotNone(response.context.get("form").errors) | ||
|
||
def test_successful_signin(self): | ||
form_data = { | ||
"username": "[email protected]", | ||
"password": "testuser@password", | ||
} | ||
|
||
response = self.client.post(self.signin_path, form_data, follow=True) | ||
self.assertEqual(response.status_code, 200) | ||
|
||
def test_unsuccessful_signin(self): | ||
form_data = { | ||
"username": "[email protected]", | ||
"password": "testuser", | ||
} | ||
|
||
response = self.client.post(self.signin_path, form_data, follow=True) | ||
form_errors = response.context.get("form").errors | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertIsNotNone(form_errors) |
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