generated from SverreNystad/template_python_application
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Remove email test as user creation does not need emails
- Loading branch information
1 parent
aa3794a
commit 32385f0
Showing
1 changed file
with
16 additions
and
41 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 |
---|---|---|
|
@@ -2,18 +2,17 @@ | |
from rest_framework import status | ||
import json | ||
from users.models import User | ||
|
||
# Create your tests here. | ||
|
||
base = "/api/" | ||
|
||
|
||
class UserCreationTests(TestCase): | ||
|
||
def setUp(self): | ||
# This code will run before each test | ||
self.register_end_point = f"{base}create-user/" | ||
self.user = User.objects.create_user( | ||
username='testuser', password='12345') | ||
self.user = User.objects.create_user(username="testuser", password="12345") | ||
self.valid_username = "username" | ||
|
||
def tearDown(self): | ||
|
@@ -29,7 +28,7 @@ def test_valid_nonexistent_user(self): | |
"email": "[email protected]", | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
"streak_count": 1, | ||
} | ||
response = client.post(self.register_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
@@ -47,7 +46,7 @@ def test_username_blank(self): | |
"email": "[email protected]", | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
"streak_count": 1, | ||
} | ||
response = client.post(self.register_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
@@ -62,7 +61,7 @@ def test_username_too_long(self): | |
"email": "[email protected]", | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
"streak_count": 1, | ||
} | ||
response = client.post(self.register_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
@@ -75,7 +74,7 @@ def test_register_already_existing_user(self): | |
"email": "[email protected]", | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
"streak_count": 1, | ||
} | ||
|
||
response = client.post(self.register_end_point, request_body) | ||
|
@@ -90,36 +89,21 @@ def test_valid_email(self): | |
"email": valid_email, | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
"streak_count": 1, | ||
} | ||
|
||
response = client.post(self.register_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_201_CREATED) | ||
|
||
def test_invalid_email(self): | ||
client = Client() | ||
invalid_email: str = "testtest.com" | ||
request_body = { | ||
"username": "username", | ||
"password": "test", | ||
"email": invalid_email, | ||
"first_name": "simon", | ||
"last_name": "sandvik", | ||
"streak_count": 1 | ||
} | ||
|
||
response = client.post(self.register_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) | ||
|
||
|
||
class LoginTests(TestCase): | ||
|
||
def setUp(self): | ||
self.login_end_point = f"{base}login/" | ||
# This code will run before each test | ||
self.user_pasword = 'a12345' | ||
self.user_pasword = "a12345" | ||
self.user = User.objects.create_user( | ||
username='logintestuser', password=self.user_pasword) | ||
username="logintestuser", password=self.user_pasword | ||
) | ||
|
||
def tearDown(self): | ||
# This code will run after each test | ||
|
@@ -146,7 +130,7 @@ def test_invalid_login_attempt_to_non_existing_valid_user(self): | |
invalid_password: str = "P21241!,.$" | ||
request_body: dict = { | ||
"username": invalid_username, | ||
"password": invalid_password | ||
"password": invalid_password, | ||
} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
|
@@ -157,7 +141,7 @@ def test_invalid_login_on_existing_user_with_capital_letters_in_username(self): | |
client = Client() | ||
request_body = { | ||
"username": str(self.user.username).upper(), | ||
"password": self.user_pasword | ||
"password": self.user_pasword, | ||
} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
|
@@ -167,38 +151,29 @@ def test_invalid_login_on_existing_user_with_capital_letters_in_password(self): | |
client = Client() | ||
request_body = { | ||
"username": self.user.username, | ||
"password": str(self.user_pasword).upper() | ||
"password": str(self.user_pasword).upper(), | ||
} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_valid_login_on_existing_user(self): | ||
client = Client() | ||
request_body = { | ||
"username": self.user.username, | ||
"password": self.user_pasword | ||
} | ||
request_body = {"username": self.user.username, "password": self.user_pasword} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
|
||
def test_correct_username_valid_on_existing_user(self): | ||
client = Client() | ||
request_body = { | ||
"username": self.user.username, | ||
"password": "WRONG-PASSWORD" | ||
} | ||
request_body = {"username": self.user.username, "password": "WRONG-PASSWORD"} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_correct_pass_valid_on_existing_user(self): | ||
client = Client() | ||
request_body = { | ||
"username": "WRONG-PASSWORD", | ||
"password": self.user_pasword | ||
} | ||
request_body = {"username": "WRONG-PASSWORD", "password": self.user_pasword} | ||
|
||
response = client.post(self.login_end_point, request_body) | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) |