core: accounts: split test file
This commit is contained in:
parent
2c7bbb5a5f
commit
a6a86a67a5
@ -1,264 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
||||||
from django.test.client import Client
|
|
||||||
from django.http import HttpResponse
|
|
||||||
import uuid
|
|
||||||
|
|
||||||
from .status_code import *
|
|
||||||
from .settings import *
|
|
||||||
|
|
||||||
class RegisterTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url: str = "/api/accounts/register"
|
|
||||||
|
|
||||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
|
||||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
|
|
||||||
def test_incomplet_form_no_username_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url)
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_incomplet_form_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_incomplet_form_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, "error: username invalid")
|
|
||||||
|
|
||||||
def test_incomplet_form_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_normal_register(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USER_ADDED)
|
|
||||||
|
|
||||||
def test_username_too_short(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": "a" * (USERNAME_MIN_SIZE - (USERNAME_MIN_SIZE > 0)), "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_username_too_long(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": "a" * (USERNAME_MAX_SIZE + 1), "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_password_too_short(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": "a" * (PASSWORD_MIN_SIZE - (PASSWORD_MIN_SIZE > 0))})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_password_too_long(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": "a" * (PASSWORD_MAX_SIZE + 1)})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_already_registered(self):
|
|
||||||
self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USERNAME_ALREADY_USED)
|
|
||||||
|
|
||||||
class LoginTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url = "/api/accounts/login"
|
|
||||||
|
|
||||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
|
||||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
|
|
||||||
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
|
||||||
|
|
||||||
def test_normal_login(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USER_VALID)
|
|
||||||
|
|
||||||
def test_invalid_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME)
|
|
||||||
|
|
||||||
class LoginTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url = "/api/accounts/login"
|
|
||||||
|
|
||||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
|
||||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
|
|
||||||
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
|
||||||
|
|
||||||
def test_normal_login(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USER_VALID)
|
|
||||||
|
|
||||||
def test_invalid_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
class DeleteTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url = "/api/accounts/delete"
|
|
||||||
|
|
||||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
|
||||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
|
|
||||||
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
|
||||||
|
|
||||||
def test_invalid_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_normal_delete(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USER_DELETED)
|
|
||||||
|
|
||||||
class ChangePasswordTest(TestCase):
|
|
||||||
def setUp(self):
|
|
||||||
self.client = Client()
|
|
||||||
|
|
||||||
self.url = "/api/accounts/change_password"
|
|
||||||
|
|
||||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
|
||||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
self.new_password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
|
||||||
|
|
||||||
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
|
||||||
|
|
||||||
def test_normal_login(self):
|
|
||||||
response: HttpResponse = self.client.post("/api/accounts/login", {"username": self.username, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, USER_VALID)
|
|
||||||
|
|
||||||
def test_invalid_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_invalid_no_password_no_username(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_no_new_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_new_password_to_short(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": "a" * (PASSWORD_MIN_SIZE - (PASSWORD_MIN_SIZE > 0))})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_new_password_to_long(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": "a" * (PASSWORD_MAX_SIZE + 1)})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
|
||||||
|
|
||||||
def test_normal_change_password(self):
|
|
||||||
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": self.new_password})
|
|
||||||
response_text: str = response.content.decode("utf-8")
|
|
||||||
self.assertEqual(response_text, PASSWORD_UPDATED)
|
|
4
django/trancendence/accounts/tests/__init__.py
Normal file
4
django/trancendence/accounts/tests/__init__.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
from .register import *
|
||||||
|
from .login import *
|
||||||
|
from .change_password import *
|
||||||
|
from .delete import *
|
76
django/trancendence/accounts/tests/change_password.py
Normal file
76
django/trancendence/accounts/tests/change_password.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from ..status_code import *
|
||||||
|
from ..settings import *
|
||||||
|
|
||||||
|
class ChangePasswordTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
|
self.url = "/api/accounts/change_password"
|
||||||
|
|
||||||
|
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
||||||
|
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||||
|
self.new_password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||||
|
|
||||||
|
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
||||||
|
|
||||||
|
def test_normal_login(self):
|
||||||
|
response: HttpResponse = self.client.post("/api/accounts/login", {"username": self.username, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, USER_VALID)
|
||||||
|
|
||||||
|
def test_invalid_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_no_new_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_new_password_to_short(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": "a" * (PASSWORD_MIN_SIZE - (PASSWORD_MIN_SIZE > 0))})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_new_password_to_long(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": "a" * (PASSWORD_MAX_SIZE + 1)})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_normal_change_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "current_password": self.password, "new_password": self.new_password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, PASSWORD_UPDATED)
|
55
django/trancendence/accounts/tests/delete.py
Normal file
55
django/trancendence/accounts/tests/delete.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from ..status_code import *
|
||||||
|
from ..settings import *
|
||||||
|
|
||||||
|
class DeleteTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
|
self.url = "/api/accounts/delete"
|
||||||
|
|
||||||
|
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
||||||
|
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||||
|
|
||||||
|
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
||||||
|
|
||||||
|
def test_invalid_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_normal_delete(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, USER_DELETED)
|
50
django/trancendence/accounts/tests/login.py
Normal file
50
django/trancendence/accounts/tests/login.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from ..status_code import *
|
||||||
|
from ..settings import *
|
||||||
|
|
||||||
|
class LoginTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
|
self.url = "/api/accounts/login"
|
||||||
|
|
||||||
|
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
||||||
|
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||||
|
|
||||||
|
self.client.post("/api/accounts/register", {"username": self.username, "password": self.password})
|
||||||
|
|
||||||
|
def test_normal_login(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, USER_VALID)
|
||||||
|
|
||||||
|
def test_invalid_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.password, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_invalid_no_password_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
69
django/trancendence/accounts/tests/register.py
Normal file
69
django/trancendence/accounts/tests/register.py
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
|
from django.test.client import Client
|
||||||
|
from django.http import HttpResponse
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
from ..status_code import *
|
||||||
|
from ..settings import *
|
||||||
|
|
||||||
|
class RegisterTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.client = Client()
|
||||||
|
|
||||||
|
self.url: str = "/api/accounts/register"
|
||||||
|
|
||||||
|
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
||||||
|
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||||
|
|
||||||
|
def test_incomplet_form_no_username_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url)
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_incomplet_form_no_password(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_incomplet_form_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, "error: username invalid")
|
||||||
|
|
||||||
|
def test_incomplet_form_no_username(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_normal_register(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, USER_ADDED)
|
||||||
|
|
||||||
|
def test_username_too_short(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": "a" * (USERNAME_MIN_SIZE - (USERNAME_MIN_SIZE > 0)), "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_username_too_long(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": "a" * (USERNAME_MAX_SIZE + 1), "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_password_too_short(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": "a" * (PASSWORD_MIN_SIZE - (PASSWORD_MIN_SIZE > 0))})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_password_too_long(self):
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": "a" * (PASSWORD_MAX_SIZE + 1)})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, INVALID_USERNAME_PASSWORD)
|
||||||
|
|
||||||
|
def test_already_registered(self):
|
||||||
|
self.client.post(self.url, {"username": self.username, "password": self.password})
|
||||||
|
response: HttpResponse = self.client.post(self.url, {"username": self.username, "password": self.password})
|
||||||
|
response_text: str = response.content.decode("utf-8")
|
||||||
|
self.assertEqual(response_text, USERNAME_ALREADY_USED)
|
Loading…
Reference in New Issue
Block a user