mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 20:17:10 +00:00
rewrite tests on signup
This commit is contained in:
@@ -1,29 +1,60 @@
|
|||||||
from django.core.exceptions import ValidationError
|
import json
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from apps.user.models import User
|
from apps.user.models import User
|
||||||
|
|
||||||
|
|
||||||
class TestSignUp(TestCase):
|
class SignUpAPITestCase(TestCase):
|
||||||
def test_correct_signup(self):
|
def test_successful_sign_up(self):
|
||||||
user = User(
|
payload = {
|
||||||
email="123123@timka.su",
|
"email": "user@example.com",
|
||||||
password="1321312",
|
"password": "securepassword123",
|
||||||
username="123123",
|
"username": "123",
|
||||||
|
}
|
||||||
|
response = self.client.post(
|
||||||
|
"/api/v1/sign-up",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
user.full_clean()
|
self.assertEqual(response.status_code, 201)
|
||||||
user.save()
|
self.assertIn("token", response.json())
|
||||||
|
self.assertEqual(User.objects.count(), 1)
|
||||||
|
|
||||||
def test_incorrect_mail(self):
|
def test_missing_required_fields(self):
|
||||||
user = User(
|
payload = {"password": "testpass123", "username": "sffsdf"}
|
||||||
email="123123",
|
response = self.client.post(
|
||||||
password="1321312",
|
"/api/v1/sign-up",
|
||||||
username="123123123",
|
data=json.dumps(payload),
|
||||||
|
content_type="application/json",
|
||||||
)
|
)
|
||||||
with self.assertRaises(ValidationError):
|
self.assertEqual(response.status_code, 400)
|
||||||
user.full_clean()
|
|
||||||
|
|
||||||
def test_missing_params(self):
|
def test_invalid_email_format(self):
|
||||||
user = User(password="123123", username="132131232131")
|
payload = {
|
||||||
with self.assertRaises(ValidationError):
|
"email": "ervtb uktr bym",
|
||||||
user.full_clean()
|
"password": "securepassword123",
|
||||||
|
"username": "123",
|
||||||
|
}
|
||||||
|
response = self.client.post(
|
||||||
|
"/api/v1/sign-up",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
content_type="application/json",
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 400)
|
||||||
|
|
||||||
|
def test_existing_user_conflict(self):
|
||||||
|
User.objects.create(
|
||||||
|
email="existing@example.com", password="existingpass123", username="testing"
|
||||||
|
)
|
||||||
|
payload = {
|
||||||
|
"email": "existing@example.com",
|
||||||
|
"password": "sfsad",
|
||||||
|
"username": "testing",
|
||||||
|
}
|
||||||
|
response = self.client.post(
|
||||||
|
"/api/v1/sign-up",
|
||||||
|
data=json.dumps(payload),
|
||||||
|
content_type="application/json",
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 409)
|
||||||
|
self.assertIn("detail", response.json())
|
||||||
|
|||||||
Reference in New Issue
Block a user