def test_view_uses_correct_template_with_get_request(self):
     ec = EmergencyContact.objects.create(full_name='Don Gately',
                                          relationship='Buddy',
                                          user=self.user)
     request = self.factory.get('/fake/')
     request.user = self.user
     response = EmergencyContactDeleteView.as_view()(request, pk=ec.id)
     self.assertTrue('emerg_contact/delete.html' in response.template_name)
 def test_post_request_redirects_to_login_if_user_not_logged_in(self):
     '''POST'''
     request = self.factory.post('/fake/')
     request.user = ''
     response = EmergencyContactDeleteView.as_view()(request)
     self.assertEqual(response.status_code, 302)
     redirect_url = reverse('authentication:login') + '?next=' + '/fake/'
     self.assertEqual(response.url, redirect_url)
 def test_200_response_from_get_request(self):
     ec = EmergencyContact.objects.create(full_name='Don Gately',
                                          relationship='Buddy',
                                          user=self.user)
     request = self.factory.get('/fake/')
     request.user = self.user
     response = EmergencyContactDeleteView.as_view()(request, pk=ec.id)
     self.assertEqual(response.status_code, 200)
 def test_post_redirects_to_list_view_if_user_is_logged_in(self):
     ec = EmergencyContact.objects.create(full_name='Don Gately',
                                          relationship='Buddy',
                                          user=self.user)
     request = self.factory.post('/fake/')
     request.user = self.user
     response = EmergencyContactDeleteView.as_view()(request, pk=ec.id)
     self.assertEqual(response.status_code, 302)
     self.assertEqual(response.url,
                      reverse('account_info:emerg_contact_list'))