Skip to content

Commit

Permalink
Add tests and update requirements for Postgres binary
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhprabhakaran3 committed Oct 23, 2023
1 parent 81ad35d commit 372f52d
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 2 deletions.
81 changes: 80 additions & 1 deletion corpus/accounts/tests.py
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)
2 changes: 1 addition & 1 deletion corpus/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ Django==4.2.4
gunicorn==21.2.0
packaging==23.1
Pillow==10.0.0
psycopg2==2.9.7
psycopg2-binary==2.9.9
sqlparse==0.4.4

0 comments on commit 372f52d

Please sign in to comment.