Reorder alpha core tests

This commit is contained in:
Christopher C. Wells 2022-05-27 16:23:38 -07:00 committed by Christopher Charbonneau Wells
parent 5b7bd52a41
commit 3af2aee093
3 changed files with 158 additions and 158 deletions

View File

@ -194,47 +194,6 @@ class ChildFormsTestCase(FormsTestCaseBase):
self.assertContains(page, "Child entry deleted")
class PumpingFormsTestCase(FormsTestCaseBase):
@classmethod
def setUpClass(cls):
super(PumpingFormsTestCase, cls).setUpClass()
cls.bp = models.Pumping.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("/pumping/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Pumping 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("/pumping/{}/".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, "Pumping entry for {} updated".format(str(self.bp.child))
)
def test_delete(self):
page = self.c.post("/pumping/{}/delete/".format(self.bp.id), follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Pumping entry deleted")
class DiaperChangeFormsTestCase(FormsTestCaseBase):
@classmethod
def setUpClass(cls):
@ -336,6 +295,149 @@ class FeedingFormsTestCase(FormsTestCaseBase):
self.assertContains(page, "Feeding entry deleted")
class NotesFormsTest(FormsTestCaseBase):
"""
Piggy-backs a bunch of tests for the tags-logic.
"""
@classmethod
def setUpClass(cls):
super(NotesFormsTest, cls).setUpClass()
cls.note = models.Note.objects.create(
child=cls.child,
note="Setup note",
time=timezone.now() - timezone.timedelta(days=2),
)
cls.note.tags.add("oldtag")
cls.oldtag = models.Tag.objects.filter(slug="oldtag").first()
def test_add_no_tags(self):
params = {
"child": self.child.id,
"note": "note with no tags",
"time": (timezone.now() - timezone.timedelta(minutes=1)).isoformat(),
}
page = self.c.post("/notes/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "note with no tags")
def test_add_with_tags(self):
params = {
"child": self.child.id,
"note": "this note has tags",
"time": (timezone.now() - timezone.timedelta(minutes=1)).isoformat(),
"tags": 'A,B,"setup tag"',
}
old_notes = list(models.Note.objects.all())
page = self.c.post("/notes/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "this note has tags")
new_notes = list(models.Note.objects.all())
# Find the new tag and extract its tags
old_pks = [n.pk for n in old_notes]
new_note = [n for n in new_notes if n.pk not in old_pks][0]
new_note_tag_names = [t.name for t in new_note.tags.all()]
self.assertSetEqual(set(new_note_tag_names), {"A", "B", "setup tag"})
def test_edit(self):
old_tag_last_used = self.oldtag.last_used
params = {
"child": self.note.child.id,
"note": "Edited note",
"time": self.localdate_string(),
"tags": "oldtag,newtag",
}
page = self.c.post("/notes/{}/".format(self.note.id), params, follow=True)
self.assertEqual(page.status_code, 200)
self.note.refresh_from_db()
self.oldtag.refresh_from_db()
self.assertEqual(self.note.note, params["note"])
self.assertContains(
page, "Note entry for {} updated".format(str(self.note.child))
)
self.assertSetEqual(
set(t.name for t in self.note.tags.all()), {"oldtag", "newtag"}
)
# Old tag remains old, because it was not added
self.assertEqual(old_tag_last_used, self.oldtag.last_used)
# Second phase: Remove all tags then add "oldtag" through posting
# which should update the last_used tag
self.note.tags.clear()
self.note.save()
params = {
"child": self.note.child.id,
"note": "Edited note (2)",
"time": self.localdate_string(),
"tags": "oldtag",
}
page = self.c.post("/notes/{}/".format(self.note.id), params, follow=True)
self.assertEqual(page.status_code, 200)
self.note.refresh_from_db()
self.oldtag.refresh_from_db()
self.assertLess(old_tag_last_used, self.oldtag.last_used)
def test_delete(self):
page = self.c.post("/notes/{}/delete/".format(self.note.id), follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Note entry deleted")
class PumpingFormsTestCase(FormsTestCaseBase):
@classmethod
def setUpClass(cls):
super(PumpingFormsTestCase, cls).setUpClass()
cls.bp = models.Pumping.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("/pumping/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Pumping 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("/pumping/{}/".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, "Pumping entry for {} updated".format(str(self.bp.child))
)
def test_delete(self):
page = self.c.post("/pumping/{}/delete/".format(self.bp.id), follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Pumping entry deleted")
class SleepFormsTestCase(FormsTestCaseBase):
@classmethod
def setUpClass(cls):
@ -639,105 +741,3 @@ class WeightFormsTest(FormsTestCaseBase):
page = self.c.post("/weight/{}/delete/".format(self.weight.id), follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Weight entry deleted")
class NotesFormsTest(FormsTestCaseBase):
"""
Piggy-backs a bunch of tests for the tags-logic.
"""
@classmethod
def setUpClass(cls):
super(NotesFormsTest, cls).setUpClass()
cls.note = models.Note.objects.create(
child=cls.child,
note="Setup note",
time=timezone.now() - timezone.timedelta(days=2),
)
cls.note.tags.add("oldtag")
cls.oldtag = models.Tag.objects.filter(slug="oldtag").first()
def test_add_no_tags(self):
params = {
"child": self.child.id,
"note": "note with no tags",
"time": (timezone.now() - timezone.timedelta(minutes=1)).isoformat(),
}
page = self.c.post("/notes/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "note with no tags")
def test_add_with_tags(self):
params = {
"child": self.child.id,
"note": "this note has tags",
"time": (timezone.now() - timezone.timedelta(minutes=1)).isoformat(),
"tags": 'A,B,"setup tag"',
}
old_notes = list(models.Note.objects.all())
page = self.c.post("/notes/add/", params, follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "this note has tags")
new_notes = list(models.Note.objects.all())
# Find the new tag and extract its tags
old_pks = [n.pk for n in old_notes]
new_note = [n for n in new_notes if n.pk not in old_pks][0]
new_note_tag_names = [t.name for t in new_note.tags.all()]
self.assertSetEqual(set(new_note_tag_names), {"A", "B", "setup tag"})
def test_edit(self):
old_tag_last_used = self.oldtag.last_used
params = {
"child": self.note.child.id,
"note": "Edited note",
"time": self.localdate_string(),
"tags": "oldtag,newtag",
}
page = self.c.post("/notes/{}/".format(self.note.id), params, follow=True)
self.assertEqual(page.status_code, 200)
self.note.refresh_from_db()
self.oldtag.refresh_from_db()
self.assertEqual(self.note.note, params["note"])
self.assertContains(
page, "Note entry for {} updated".format(str(self.note.child))
)
self.assertSetEqual(
set(t.name for t in self.note.tags.all()), {"oldtag", "newtag"}
)
# Old tag remains old, because it was not added
self.assertEqual(old_tag_last_used, self.oldtag.last_used)
# Second phase: Remove all tags then add "oldtag" through posting
# which should update the last_used tag
self.note.tags.clear()
self.note.save()
params = {
"child": self.note.child.id,
"note": "Edited note (2)",
"time": self.localdate_string(),
"tags": "oldtag",
}
page = self.c.post("/notes/{}/".format(self.note.id), params, follow=True)
self.assertEqual(page.status_code, 200)
self.note.refresh_from_db()
self.oldtag.refresh_from_db()
self.assertLess(old_tag_last_used, self.oldtag.last_used)
def test_delete(self):
page = self.c.post("/notes/{}/delete/".format(self.note.id), follow=True)
self.assertEqual(page.status_code, 200)
self.assertContains(page, "Note entry deleted")

View File

@ -41,9 +41,6 @@ class ImportTestCase(TestCase):
def test_child(self):
self.import_data(models.Child, 2)
def test_pumping(self):
self.import_data(models.Pumping, 23)
def test_diaperchange(self):
self.import_data(models.DiaperChange, 75)
@ -53,6 +50,9 @@ class ImportTestCase(TestCase):
def test_note(self):
self.import_data(models.Note, 1)
def test_pumping(self):
self.import_data(models.Pumping, 23)
def test_sleep(self):
self.import_data(models.Sleep, 39)

View File

@ -49,18 +49,6 @@ class ViewsTestCase(TestCase):
page = self.c.get("/children/{}/delete/".format(entry.slug))
self.assertEqual(page.status_code, 200)
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)
def test_diaperchange_views(self):
page = self.c.get("/changes/")
self.assertEqual(page.status_code, 200)
@ -97,6 +85,18 @@ class ViewsTestCase(TestCase):
page = self.c.get("/notes/{}/delete/".format(entry.id))
self.assertEqual(page.status_code, 200)
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)
def test_sleep_views(self):
page = self.c.get("/sleep/")
self.assertEqual(page.status_code, 200)