blob: 66cad8d11f8f1ffcb349c3945042109b96208ce8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
from io import StringIO
import pytest
from django.core.management import call_command
from pyblackbird_cc.users.models import User
@pytest.mark.django_db()
class TestUserManager:
def test_create_user(self):
user = User.objects.create_user(
email="john@example.com",
password="something-r@nd0m!", # noqa: S106
)
assert user.email == "john@example.com"
assert not user.is_staff
assert not user.is_superuser
assert user.check_password("something-r@nd0m!")
assert user.username is None
def test_create_superuser(self):
user = User.objects.create_superuser(
email="admin@example.com",
password="something-r@nd0m!", # noqa: S106
)
assert user.email == "admin@example.com"
assert user.is_staff
assert user.is_superuser
assert user.username is None
def test_create_superuser_username_ignored(self):
user = User.objects.create_superuser(
email="test@example.com",
password="something-r@nd0m!", # noqa: S106
)
assert user.username is None
@pytest.mark.django_db()
def test_createsuperuser_command():
"""Ensure createsuperuser command works with our custom manager."""
out = StringIO()
command_result = call_command(
"createsuperuser",
"--email",
"henry@example.com",
interactive=False,
stdout=out,
)
assert command_result is None
assert out.getvalue() == "Superuser created successfully.\n"
user = User.objects.get(email="henry@example.com")
assert not user.has_usable_password()
|