From 32385f07d498559f2aaefa22f3a86947fb5efacc Mon Sep 17 00:00:00 2001 From: Sverre Nystad Date: Fri, 5 Jan 2024 22:44:02 +0100 Subject: [PATCH] Feat: Remove email test as user creation does not need emails --- backend/users/tests.py | 57 ++++++++++++------------------------------ 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/backend/users/tests.py b/backend/users/tests.py index 55c87b3..f79122d 100644 --- a/backend/users/tests.py +++ b/backend/users/tests.py @@ -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": "test@test.com", "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": "test@test.com", "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": "test@test.com", "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": "test@test.com", "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,7 +151,7 @@ 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) @@ -175,30 +159,21 @@ def test_invalid_login_on_existing_user_with_capital_letters_in_password(self): 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)