def test_missing_sign_view_renders_right_template(self): ''' The missing sign view should render the 'feedback/missingsign_form.html' template ''' request = create_request(self.url, 'get') with self.assertTemplateUsed('feedback/missingsign_form.html'): response = missingsign(request)
def test_missing_sign_view_redirects_after_a_successful_post_request(self): ''' The missign sign view should redirect back to itself after receiving valid feedback. ''' request = create_request(self.url, 'post', self.data) response = missingsign(request) self.assertEqual(response.status_code, 302) self.assertEqual(response.url, self.url)
def test_missing_sign_view_returns_200_response_code_for_a_get_request( self): ''' The response code reutrned by the missing sign view should be 200 for a get request. ''' request = create_request(self.url, 'get') response = missingsign(request) self.assertEqual(response.status_code, 200)
def test_error_is_displayed_if_neither_comment_nor_meaning_is_submitted( self): ''' Not submitting a comment should render an error on the form. ''' request = create_request(self.url, 'post') response = missingsign(request) self.assertContains(response, 'This field is required', count=2, status_code=200)
def test_missing_sign_view_saves_to_database(self): ''' The missing sign view should save feedback to database after being submitted. ''' request = create_request(self.url, 'post', self.data) response = missingsign(request) # Now, let's make sure that the feedback is in the database feedback = MissingSignFeedback.objects.all() # There should be one feedback in the datbase self.assertEqual(1, len(feedback)) # It should have a date self.assertIsInstance(feedback[0].date, datetime.date) self.assertEqual(feedback[0].date, datetime.date.today()) # It should have a comment self.assertEqual(feedback[0].comment, self.data['comment']) # It should have a meaning self.assertEqual(feedback[0].meaning, self.data['meaning'])