mybuddy/babybuddy/tests/tests_commands.py

62 lines
1.9 KiB
Python
Raw Normal View History

2017-11-11 22:25:28 +00:00
# -*- coding: utf-8 -*-
from django.test import TransactionTestCase
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
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)
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()
)
self.assertEqual(Child.objects.count(), 1)
def test_createuser(self):
call_command(
"createuser",
username="test",
email="test@test.test",
password="test",
verbosity=0,
)
2023-02-08 04:29:15 +00:00
self.assertIsInstance(
get_user_model().objects.get(username="test"), get_user_model()
)
self.assertFalse(
2023-02-08 04:29:15 +00:00
get_user_model().objects.filter(
username="test", is_staff=True, is_superuser=True
)
)
call_command(
"createuser",
"--is-staff",
username="testadmin",
email="testadmin@testadmin.testadmin",
password="test",
verbosity=0,
)
2023-02-08 04:29:15 +00:00
self.assertIsInstance(
get_user_model().objects.get(username="testadmin"), get_user_model()
)
self.assertTrue(
2023-02-08 04:29:15 +00:00
get_user_model().objects.filter(
username="testadmin", is_staff=True, is_superuser=True
)
)