2017-10-22 02:14:44 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-02-06 14:59:57 +00:00
|
|
|
from django.contrib.auth import get_user_model
|
2017-10-22 02:14:44 +00:00
|
|
|
from django.core.management import call_command
|
2017-11-10 02:15:09 +00:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.test import Client as HttpClient
|
|
|
|
from django.utils import timezone
|
2017-10-22 02:14:44 +00:00
|
|
|
|
2022-05-28 02:56:38 +00:00
|
|
|
from faker import Faker
|
2017-10-22 02:14:44 +00:00
|
|
|
|
|
|
|
from core import models
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
call_command("fake", verbosity=0)
|
2017-10-22 02:14:44 +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-22 02:14:44 +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-22 02:14:44 +00:00
|
|
|
|
|
|
|
cls.c.login(**cls.credentials)
|
|
|
|
|
2022-05-28 13:41:37 +00:00
|
|
|
def test_bmi_views(self):
|
|
|
|
page = self.c.get("/bmi/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/bmi/add/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.BMI.objects.first()
|
|
|
|
page = self.c.get("/bmi/{}/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/bmi/{}/delete/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2017-10-22 02:14:44 +00:00
|
|
|
def test_child_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Child.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/{}/".format(entry.slug))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2017-11-10 02:15:09 +00:00
|
|
|
page = self.c.get(
|
2022-02-10 00:00:30 +00:00
|
|
|
"/children/{}/".format(entry.slug),
|
|
|
|
{"date": timezone.localdate() - timezone.timedelta(days=1)},
|
|
|
|
)
|
2017-11-10 02:15:09 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/{}/edit/".format(entry.slug))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/children/{}/delete/".format(entry.slug))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
def test_diaperchange_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/changes/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/changes/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.DiaperChange.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/changes/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/changes/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
def test_feeding_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/feedings/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/feedings/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Feeding.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/feedings/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/feedings/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-05-28 13:41:37 +00:00
|
|
|
|
|
|
|
def test_headcircumference_views(self):
|
|
|
|
page = self.c.get("/head-circumference/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/head-circumference/add/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.HeadCircumference.objects.first()
|
|
|
|
page = self.c.get("/head-circumference/{}/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/head-circumference/{}/delete/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
def test_height_views(self):
|
|
|
|
page = self.c.get("/height/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/height/add/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Height.objects.first()
|
|
|
|
page = self.c.get("/height/{}/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/height/{}/delete/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
2017-10-22 02:14:44 +00:00
|
|
|
|
|
|
|
def test_note_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/notes/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/notes/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Note.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/notes/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/notes/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2022-05-27 23:23:38 +00:00
|
|
|
def test_pumping_views(self):
|
|
|
|
page = self.c.get("/pumping/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/pumping/add/")
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Pumping.objects.first()
|
|
|
|
page = self.c.get("/pumping/{}/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
page = self.c.get("/pumping/{}/delete/".format(entry.id))
|
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2017-10-22 02:14:44 +00:00
|
|
|
def test_sleep_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/sleep/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/sleep/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Sleep.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/sleep/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/sleep/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2019-05-17 04:33:26 +00:00
|
|
|
def test_temperature_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/temperature/")
|
2019-05-17 04:33:26 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/temperature/add/")
|
2019-05-17 04:33:26 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Temperature.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/temperature/{}/".format(entry.id))
|
2019-05-17 04:33:26 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/temperature/{}/delete/".format(entry.id))
|
2019-05-17 04:33:26 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2017-10-22 02:14:44 +00:00
|
|
|
def test_timer_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/add/quick/")
|
2021-07-31 20:56:48 +00:00
|
|
|
self.assertEqual(page.status_code, 405)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.post("/timers/add/quick/", follow=True)
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2017-10-22 02:14:44 +00:00
|
|
|
entry = models.Timer.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/{}/edit/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2021-07-31 20:11:21 +00:00
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/{}/stop/".format(entry.id))
|
2021-07-31 20:11:21 +00:00
|
|
|
self.assertEqual(page.status_code, 405)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.post("/timers/{}/stop/".format(entry.id), follow=True)
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2021-07-31 20:11:21 +00:00
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/{}/restart/".format(entry.id))
|
2021-07-31 20:11:21 +00:00
|
|
|
self.assertEqual(page.status_code, 405)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.post("/timers/{}/restart/".format(entry.id), follow=True)
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/delete-inactive/", follow=True)
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
messages = list(page.context["messages"])
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(len(messages), 1)
|
2022-02-10 00:00:30 +00:00
|
|
|
self.assertEqual(str(messages[0]), "No inactive timers exist.")
|
2020-02-07 05:50:22 +00:00
|
|
|
|
|
|
|
entry = models.Timer.objects.first()
|
|
|
|
entry.stop()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/timers/delete-inactive/")
|
2020-02-07 05:50:22 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
self.assertEqual(page.context["timer_count"], 1)
|
2017-10-22 02:14:44 +00:00
|
|
|
|
2021-08-30 23:01:20 +00:00
|
|
|
def test_timeline_views(self):
|
|
|
|
child = models.Child.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
response = self.c.get("/timeline/")
|
|
|
|
self.assertRedirects(response, "/children/{}/".format(child.slug))
|
2021-08-30 23:01:20 +00:00
|
|
|
|
|
|
|
models.Child.objects.create(
|
2022-02-10 00:00:30 +00:00
|
|
|
first_name="Second", last_name="Child", birth_date="2000-01-01"
|
2021-08-30 23:01:20 +00:00
|
|
|
)
|
2022-02-10 00:00:30 +00:00
|
|
|
response = self.c.get("/timeline/")
|
2021-08-30 23:01:20 +00:00
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
2017-10-22 02:14:44 +00:00
|
|
|
def test_tummytime_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/tummy-time/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/tummy-time/add/")
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.TummyTime.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/tummy-time/{}/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/tummy-time/{}/delete/".format(entry.id))
|
2017-10-22 02:14:44 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
def test_weight_views(self):
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/weight/")
|
2017-11-10 02:15:09 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/weight/add/")
|
2017-11-10 02:15:09 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
|
|
|
|
|
|
|
entry = models.Weight.objects.first()
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/weight/{}/".format(entry.id))
|
2017-11-10 02:15:09 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|
2022-02-10 00:00:30 +00:00
|
|
|
page = self.c.get("/weight/{}/delete/".format(entry.id))
|
2017-11-10 02:15:09 +00:00
|
|
|
self.assertEqual(page.status_code, 200)
|