register: use ModelForm, and print all errors
This commit is contained in:
@ -3,10 +3,11 @@ from django.test import TestCase
|
||||
# Create your tests here.
|
||||
from django.test.client import Client
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
import uuid
|
||||
|
||||
from ..status_code import *
|
||||
from ..settings import *
|
||||
|
||||
class DeleteTest(TestCase):
|
||||
def setUp(self):
|
||||
@ -14,42 +15,20 @@ class DeleteTest(TestCase):
|
||||
|
||||
self.url = "/api/accounts/delete"
|
||||
|
||||
self.username: str = str(uuid.uuid4())[:USERNAME_MAX_SIZE]
|
||||
self.password: str = str(uuid.uuid4())[:PASSWORD_MAX_SIZE]
|
||||
self.username: str = str(uuid.uuid4())
|
||||
self.password: str = str(uuid.uuid4())
|
||||
|
||||
user: User = User.objects.create_user(username=self.username, password=self.password)
|
||||
self.client.login(username=self.username, password=self.password)
|
||||
|
||||
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: HttpResponse = self.client.post(self.url)
|
||||
response_text: str = response.content.decode("utf-8")
|
||||
self.assertEqual(response_text, USER_DELETED)
|
||||
self.assertEqual(response_text, USER_DELETED)
|
||||
|
||||
def test_no_logged(self):
|
||||
self.client.logout()
|
||||
response: HttpResponse = self.client.post(self.url)
|
||||
response_text: str = response.content.decode("utf-8")
|
||||
self.assertEqual(response_text, '')
|
Reference in New Issue
Block a user