mirror of https://github.com/snachodog/mybuddy.git
add tests
This commit is contained in:
parent
97b1b8d9ce
commit
44648ce33b
46
api/tests.py
46
api/tests.py
|
@ -129,6 +129,52 @@ class ChildAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
self.assertEqual(response.data, entry)
|
self.assertEqual(response.data, entry)
|
||||||
|
|
||||||
|
|
||||||
|
class BreastpumpAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
|
endpoint = reverse("api:breastpump-list")
|
||||||
|
model = models.Breastpump
|
||||||
|
|
||||||
|
def test_get(self):
|
||||||
|
response = self.client.get(self.endpoint)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(
|
||||||
|
response.data["results"][0],
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"child": 1,
|
||||||
|
"amount": 50.0,
|
||||||
|
"time": "2017-11-17T12:52:00-05:00",
|
||||||
|
"notes": "new device",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_post(self):
|
||||||
|
data = {
|
||||||
|
"child": 1,
|
||||||
|
"amount": "21",
|
||||||
|
"time": "2017-11-20T22:52:00-05:00",
|
||||||
|
"notes": "old device",
|
||||||
|
}
|
||||||
|
response = self.client.post(self.endpoint, data, format="json")
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||||
|
obj = models.Breastpump.objects.get(pk=response.data["id"])
|
||||||
|
self.assertEqual(str(obj.amount), data["amount"])
|
||||||
|
self.assertEqual(obj.notes, data["notes"])
|
||||||
|
|
||||||
|
def test_patch(self):
|
||||||
|
endpoint = "{}{}/".format(self.endpoint, 1)
|
||||||
|
response = self.client.get(endpoint)
|
||||||
|
entry = response.data
|
||||||
|
entry["amount"] = 41
|
||||||
|
response = self.client.patch(
|
||||||
|
endpoint,
|
||||||
|
{
|
||||||
|
"amount": entry["amount"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data, entry)
|
||||||
|
|
||||||
|
|
||||||
class DiaperChangeAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
class DiaperChangeAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
endpoint = reverse("api:diaperchange-list")
|
endpoint = reverse("api:diaperchange-list")
|
||||||
model = models.DiaperChange
|
model = models.DiaperChange
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
child_id,amount,time
|
||||||
|
1,100.2,2020-02-17 09:31:49
|
||||||
|
1,99.62,2020-02-17 04:11:09
|
||||||
|
1,101.45,2020-02-17 00:14:09
|
||||||
|
1,97.41,2020-02-16 14:42:52
|
||||||
|
1,99.53,2020-02-16 11:28:41
|
||||||
|
1,98.92,2020-02-16 07:38:01
|
||||||
|
1,97.69,2020-02-15 22:53:01
|
||||||
|
1,98.37,2020-02-15 17:37:21
|
||||||
|
1,101.73,2020-02-15 07:51:45
|
||||||
|
1,98.31,2020-02-15 03:06:24
|
||||||
|
1,95.31,2020-02-14 12:12:28
|
||||||
|
1,99.5,2020-02-14 07:41:40
|
||||||
|
1,99.9,2020-02-13 18:05:46
|
||||||
|
1,98.33,2020-02-13 14:15:54
|
||||||
|
1,98.78,2020-02-13 09:39:03
|
||||||
|
1,98.51,2020-02-12 18:17:05
|
||||||
|
1,100.76,2020-02-12 05:54:01
|
||||||
|
1,98.96,2020-02-11 21:00:14
|
||||||
|
1,95.15,2020-02-11 17:33:04
|
||||||
|
1,95.89,2020-02-11 14:51:04
|
||||||
|
1,98.57,2020-02-11 08:30:34
|
||||||
|
1,99.16,2020-02-11 06:35:34
|
||||||
|
1,98.37,2020-02-10 10:25:06
|
|
|
@ -194,6 +194,49 @@ class ChildFormsTestCase(FormsTestCaseBase):
|
||||||
self.assertContains(page, "Child entry deleted")
|
self.assertContains(page, "Child entry deleted")
|
||||||
|
|
||||||
|
|
||||||
|
class BreastpumpFormsTestCase(FormsTestCaseBase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super(BreastpumpFormsTestCase, cls).setUpClass()
|
||||||
|
cls.bp = models.Breastpump.objects.create(
|
||||||
|
child=cls.child,
|
||||||
|
amount=50.0,
|
||||||
|
time=timezone.localtime() - timezone.timedelta(days=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_add(self):
|
||||||
|
params = {
|
||||||
|
"child": self.child.id,
|
||||||
|
"amount": "50.0",
|
||||||
|
"time": self.localtime_string(),
|
||||||
|
}
|
||||||
|
|
||||||
|
page = self.c.post("/breastpump/add/", params, follow=True)
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
self.assertContains(
|
||||||
|
page, "Breastpump entry for {} added".format(str(self.child))
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_edit(self):
|
||||||
|
params = {
|
||||||
|
"child": self.bp.child.id,
|
||||||
|
"amount": self.bp.amount + 2,
|
||||||
|
"time": self.localtime_string(),
|
||||||
|
}
|
||||||
|
page = self.c.post("/breastpump/{}/".format(self.bp.id), params, follow=True)
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
self.bp.refresh_from_db()
|
||||||
|
self.assertEqual(self.bp.amount, params["amount"])
|
||||||
|
self.assertContains(
|
||||||
|
page, "Breastpump entry for {} updated".format(str(self.bp.child))
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_delete(self):
|
||||||
|
page = self.c.post("/breastpump/{}/delete/".format(self.bp.id), follow=True)
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
self.assertContains(page, "Breastpump entry deleted")
|
||||||
|
|
||||||
|
|
||||||
class DiaperChangeFormsTestCase(FormsTestCaseBase):
|
class DiaperChangeFormsTestCase(FormsTestCaseBase):
|
||||||
@classmethod
|
@classmethod
|
||||||
def setUpClass(cls):
|
def setUpClass(cls):
|
||||||
|
|
|
@ -41,6 +41,9 @@ class ImportTestCase(TestCase):
|
||||||
def test_child(self):
|
def test_child(self):
|
||||||
self.import_data(models.Child, 2)
|
self.import_data(models.Child, 2)
|
||||||
|
|
||||||
|
def test_breastpump(self):
|
||||||
|
self.import_data(models.Breastpump, 23)
|
||||||
|
|
||||||
def test_diaperchange(self):
|
def test_diaperchange(self):
|
||||||
self.import_data(models.DiaperChange, 75)
|
self.import_data(models.DiaperChange, 75)
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,24 @@ class ChildTestCase(TestCase):
|
||||||
self.assertEqual(models.Child.count(), 1)
|
self.assertEqual(models.Child.count(), 1)
|
||||||
|
|
||||||
|
|
||||||
|
class BreastpumpTestCase(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
call_command("migrate", verbosity=0)
|
||||||
|
self.child = models.Child.objects.create(
|
||||||
|
first_name="First", last_name="Last", birth_date=timezone.localdate()
|
||||||
|
)
|
||||||
|
self.temp = models.Breastpump.objects.create(
|
||||||
|
child=self.child,
|
||||||
|
time=timezone.localtime() - timezone.timedelta(days=1),
|
||||||
|
amount=98.6,
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_breastpump_create(self):
|
||||||
|
self.assertEqual(self.temp, models.Breastpump.objects.first())
|
||||||
|
self.assertEqual(str(self.temp), "Breastpump")
|
||||||
|
self.assertEqual(self.temp.amount, 98.6)
|
||||||
|
|
||||||
|
|
||||||
class DiaperChangeTestCase(TestCase):
|
class DiaperChangeTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
call_command("migrate", verbosity=0)
|
call_command("migrate", verbosity=0)
|
||||||
|
|
|
@ -49,6 +49,18 @@ class ViewsTestCase(TestCase):
|
||||||
page = self.c.get("/children/{}/delete/".format(entry.slug))
|
page = self.c.get("/children/{}/delete/".format(entry.slug))
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
|
def test_breastpump_views(self):
|
||||||
|
page = self.c.get("/breastpump/")
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
page = self.c.get("/breastpump/add/")
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
|
entry = models.Breastpump.objects.first()
|
||||||
|
page = self.c.get("/breastpump/{}/".format(entry.id))
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
page = self.c.get("/breastpump/{}/delete/".format(entry.id))
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
def test_diaperchange_views(self):
|
def test_diaperchange_views(self):
|
||||||
page = self.c.get("/changes/")
|
page = self.c.get("/changes/")
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
|
@ -35,6 +35,9 @@ class ViewsTestCase(TestCase):
|
||||||
page = self.c.get(base_url)
|
page = self.c.get(base_url)
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
|
page = self.c.get("{}/breastpump/amounts/".format(base_url))
|
||||||
|
self.assertEqual(page.status_code, 200)
|
||||||
|
|
||||||
page = self.c.get("{}/changes/amounts/".format(base_url))
|
page = self.c.get("{}/changes/amounts/".format(base_url))
|
||||||
self.assertEqual(page.status_code, 200)
|
self.assertEqual(page.status_code, 200)
|
||||||
page = self.c.get("{}/changes/lifetimes/".format(base_url))
|
page = self.c.get("{}/changes/lifetimes/".format(base_url))
|
||||||
|
|
Loading…
Reference in New Issue