Add tests for inactive Timer delete functionality

This commit is contained in:
Christopher C. Wells 2020-02-06 21:50:22 -08:00
parent 127c3d5cb0
commit af710b977a
2 changed files with 30 additions and 6 deletions

View File

@ -504,6 +504,17 @@ class TimerFormsTestCase(FormsTestCaseBase):
follow=True) follow=True)
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
def test_delete_inactive(self):
models.Timer.objects.create(user=self.user)
self.assertEqual(models.Timer.objects.count(), 2)
self.timer.stop()
page = self.c.post('/timers/delete-inactive/', follow=True)
self.assertEqual(page.status_code, 200)
messages = list(page.context['messages'])
self.assertEqual(len(messages), 1)
self.assertEqual(str(messages[0]), 'All inactive timers deleted.')
self.assertEqual(models.Timer.objects.count(), 1)
class ValidationsTestCase(FormsTestCaseBase): class ValidationsTestCase(FormsTestCaseBase):
def test_validate_date(self): def test_validate_date(self):

View File

@ -115,8 +115,9 @@ class ViewsTestCase(TestCase):
page = self.c.get('/timers/add/') page = self.c.get('/timers/add/')
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/add/quick/') page = self.c.get('/timers/add/quick/', follow=True)
self.assertEqual(page.status_code, 302) self.assertEqual(page.status_code, 200)
entry = models.Timer.objects.first() entry = models.Timer.objects.first()
page = self.c.get('/timers/{}/'.format(entry.id)) page = self.c.get('/timers/{}/'.format(entry.id))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
@ -124,10 +125,22 @@ class ViewsTestCase(TestCase):
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/delete/'.format(entry.id)) page = self.c.get('/timers/{}/delete/'.format(entry.id))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/stop/'.format(entry.id)) page = self.c.get('/timers/{}/stop/'.format(entry.id), follow=True)
self.assertEqual(page.status_code, 302) self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/{}/restart/'.format(entry.id)) page = self.c.get('/timers/{}/restart/'.format(entry.id), follow=True)
self.assertEqual(page.status_code, 302) self.assertEqual(page.status_code, 200)
page = self.c.get('/timers/delete-inactive/', follow=True)
self.assertEqual(page.status_code, 200)
messages = list(page.context['messages'])
self.assertEqual(len(messages), 1)
self.assertEqual(str(messages[0]), 'No inactive timers exist.')
entry = models.Timer.objects.first()
entry.stop()
page = self.c.get('/timers/delete-inactive/')
self.assertEqual(page.status_code, 200)
self.assertEqual(page.context['timer_count'], 1)
def test_tummytime_views(self): def test_tummytime_views(self):
page = self.c.get('/tummy-time/') page = self.c.get('/tummy-time/')