2017-10-25 15:05:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.test import Client as HttpClient
|
2023-02-06 14:59:57 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2017-10-25 15:05:45 +00:00
|
|
|
from django.core.management import call_command
|
|
|
|
|
2022-05-28 02:56:38 +00:00
|
|
|
from faker import Faker
|
2017-10-25 15:05:45 +00:00
|
|
|
|
|
|
|
from core.models import Child
|
|
|
|
|
|
|
|
|
|
|
|
class ViewsTestCase(TestCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(ViewsTestCase, cls).setUpClass()
|
2022-05-28 02:56:38 +00:00
|
|
|
fake = Faker()
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("migrate", verbosity=0)
|
2017-10-25 15:05:45 +00:00
|
|
|
|
|
|
|
cls.c = HttpClient()
|
|
|
|
|
|
|
|
fake_user = fake.simple_profile()
|
|
|
|
cls.credentials = {
|
2022-02-10 00:00:30 +00:00
|
|
|
"username": fake_user["username"],
|
|
|
|
"password": fake.password(),
|
2017-10-25 15:05:45 +00:00
|
|
|
}
|
2023-02-08 04:29:15 +00:00
|
|
|
cls.user = get_user_model().objects.create_user(
|
|
|
|
is_superuser=True, **cls.credentials
|
|
|
|
)
|
2017-10-25 15:05:45 +00:00
|
|
|
|
|
|
|
cls.c.login(**cls.credentials)
|
|
|
|
|
|
|
|
def test_dashboard_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/dashboard/")
|
|
|
|
self.assertEqual(page.url, "/welcome/")
|
2017-10-25 15:05:45 +00:00
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
call_command("fake", verbosity=0, children=1, days=1)
|
2017-10-25 15:05:45 +00:00
|
|
|
child = Child.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/dashboard/")
|
|
|
|
self.assertEqual(page.url, "/children/{}/dashboard/".format(child.slug))
|
2017-11-06 21:24:21 +00:00
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/dashboard/")
|
|
|
|
self.assertEqual(page.url, "/children/{}/dashboard/".format(child.slug))
|
2017-10-25 15:05:45 +00:00
|
|
|
# Test the actual child dashboard (including cards).
|
|
|
|
# TODO: Test cards more granularly.
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/{}/dashboard/".format(child.slug))
|
2017-10-25 15:05:45 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
Child.objects.create(
|
2022-02-10 00:00:30 +00:00
|
|
|
first_name="Second", last_name="Child", birth_date="2000-01-01"
|
2017-10-25 15:05:45 +00:00
|
|
|
)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/dashboard/")
|
2017-11-06 21:24:21 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|