Esempio n. 1
0
    def test_home_page_displays_all_time_items(self):
        Time.objects.create(text='time one')
        Time.objects.create(text='time two')

        request = HttpRequest()
        response = home_page(request)

        self.assertIn('time one', response.content.decode())
        self.assertIn('time two', response.content.decode())
Esempio n. 2
0
    def test_home_page_redirects_after_a_post(self):
        request = HttpRequest()
        request.method = 'POST'
        request.POST['time_text'] = 'A time entered'

        response = home_page(request)

        self.assertEqual(response.status_code, 302)
        self.assertEqual(response['location'], '/')
Esempio n. 3
0
    def test_home_page_can_save_a_POST_request(self):
        request = HttpRequest()
        request.method = 'POST'
        request.POST['time_text'] = 'A time entered'

        response = home_page(request)

        self.assertEqual(Time.objects.count(), 1)
        new_time = Time.objects.first()
        self.assertEqual(new_time.text, 'A time entered')
Esempio n. 4
0
 def test_home_page_only_saves_items_when_necessary(self):
     request = HttpRequest()
     home_page(request)
     self.assertEqual(Time.objects.count(), 0)
Esempio n. 5
0
 def test_home_page_returns_correct_html(self):
     request = HttpRequest()
     response = home_page(request)
     expected_html = render_to_string('home.html')
     self.assertEqual(response.content.decode(), expected_html)