2017-11-11 22:25:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-12-06 17:01:45 +00:00
|
|
|
from django.test import TransactionTestCase
|
2023-02-06 14:59:57 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2017-11-11 22:25:28 +00:00
|
|
|
from django.core.management import call_command
|
|
|
|
|
|
|
|
from core.models import Child
|
|
|
|
|
|
|
|
|
2017-12-06 17:01:45 +00:00
|
|
|
class CommandsTestCase(TransactionTestCase):
|
2017-11-11 22:25:28 +00:00
|
|
|
def test_migrate(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("migrate", verbosity=0)
|
2023-02-08 04:29:15 +00:00
|
|
|
self.assertIsInstance(
|
|
|
|
get_user_model().objects.get(username="admin"), get_user_model()
|
|
|
|
)
|
2017-11-11 22:25:28 +00:00
|
|
|
|
|
|
|
def test_fake(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("migrate", verbosity=0)
|
|
|
|
call_command("fake", children=1, days=7, verbosity=0)
|
2017-11-11 22:25:28 +00:00
|
|
|
self.assertEqual(Child.objects.count(), 1)
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("fake", children=2, days=7, verbosity=0)
|
2017-11-11 22:25:28 +00:00
|
|
|
self.assertEqual(Child.objects.count(), 3)
|
|
|
|
|
2017-12-06 17:01:45 +00:00
|
|
|
def test_reset(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("reset", verbosity=0, interactive=False)
|
2023-02-08 04:29:15 +00:00
|
|
|
self.assertIsInstance(
|
|
|
|
get_user_model().objects.get(username="admin"), get_user_model()
|
|
|
|
)
|
2017-12-06 17:01:45 +00:00
|
|
|
self.assertEqual(Child.objects.count(), 1)
|
2022-10-04 15:24:01 +00:00
|
|
|
|
|
|
|
def test_createuser(self):
|
|
|
|
call_command(
|
|
|
|
"createuser",
|
2023-02-09 03:33:22 +00:00
|
|
|
username="regularuser",
|
|
|
|
email="regularuser@test.test",
|
2022-10-04 15:24:01 +00:00
|
|
|
password="test",
|
|
|
|
verbosity=0,
|
|
|
|
)
|
2023-02-09 03:33:22 +00:00
|
|
|
user = get_user_model().objects.get(username="regularuser")
|
|
|
|
self.assertIsInstance(user, get_user_model())
|
|
|
|
self.assertTrue(user.is_superuser)
|
|
|
|
self.assertFalse(user.is_staff)
|
|
|
|
self.assertEqual(user.email, "regularuser@test.test")
|
|
|
|
|
2022-10-04 15:24:01 +00:00
|
|
|
call_command(
|
|
|
|
"createuser",
|
2022-10-22 06:15:49 +00:00
|
|
|
"--is-staff",
|
2023-02-09 03:33:22 +00:00
|
|
|
username="staffuser",
|
|
|
|
email="staffuser@test.test",
|
2022-10-04 15:24:01 +00:00
|
|
|
password="test",
|
|
|
|
verbosity=0,
|
|
|
|
)
|
2023-02-09 03:33:22 +00:00
|
|
|
user = get_user_model().objects.get(username="staffuser")
|
|
|
|
self.assertIsInstance(user, get_user_model())
|
|
|
|
self.assertTrue(user.is_superuser)
|
|
|
|
self.assertTrue(user.is_staff)
|
|
|
|
|
|
|
|
call_command(
|
|
|
|
"createuser",
|
|
|
|
"--read-only",
|
|
|
|
username="readonlyuser",
|
|
|
|
email="readonlyuser@test.test",
|
|
|
|
password="test",
|
|
|
|
verbosity=0,
|
2022-10-22 06:15:49 +00:00
|
|
|
)
|
2023-02-09 03:33:22 +00:00
|
|
|
user = get_user_model().objects.get(username="readonlyuser")
|
|
|
|
self.assertIsInstance(user, get_user_model())
|
|
|
|
self.assertFalse(user.is_superuser)
|
|
|
|
self.assertFalse(user.is_staff)
|
|
|
|
self.assertTrue(user.groups.filter(name="read_only").exists())
|