Exemplo n.º 1
0
 def test_post(self, handler):
     item = factories.OptOutFactory()
     url = resolve_url("django_opt_out:OptOutSuccess", item.pk, item.secret, item.email)
     response = test.Client().post(url)
     self.assertNoFormErrors(response)
     self.assertRedirects(response, resolve_url("django_opt_out:OptOutRemoved"))
     self.assertTrue(handler.called)
Exemplo n.º 2
0
 def test_initial_feedback(self):
     feedback = factories.OptOutFeedbackFactory.create_batch(7)[3:5]
     item = factories.OptOutFactory()
     item.feedback.add(*feedback)
     url = resolve_url("django_opt_out:OptOutUpdate", item.pk, item.secret, item.email)
     response = test.Client().get(url)
     self.assertEqual(200, response.status_code)
     self.assertNoFormErrors(response)
     choices = set(response.context_data['form'].fields['feedback'].initial)
     self.assertEqual(set((f.pk for f in feedback)), set(choices))
Exemplo n.º 3
0
 def test_feedback_based_on_saved_tags(self):
     feedback = factories.OptOutFeedbackFactory.create_batch(3)
     tag1 = factories.OptOutTagFactory()
     feedback.extend(factories.OptOutFeedbackFactory.create_batch(3, tags=(tag1,)))
     tag2 = factories.OptOutTagFactory()
     factories.OptOutFeedbackFactory.create_batch(3, tags=(tag2,))
     item = factories.OptOutFactory()
     item.tags.create(tag=tag1)
     url = resolve_url("django_opt_out:OptOutUpdate", item.pk, item.secret, item.email)
     response = test.Client().get(url)
     self.assertEqual(200, response.status_code)
     self.assertNoFormErrors(response)
     choices = [pk for pk, label in response.context_data['form'].fields['feedback'].choices]
     self.assertEqual(set((f.pk for f in feedback)), set(choices))
Exemplo n.º 4
0
 def test_success_url(self):
     view = views.OptOutConfirm()
     view.object = factories.OptOutFactory(pk=1, secret='7ebc5d464a6485e4b64f', email='*****@*****.**')
     url = view.get_success_url()
     self.assertEqual('/opt-out/success/1/7ebc5d464a6485e4b64f/[email protected]', url)
Exemplo n.º 5
0
 def test_overriden_success_url(self):
     view = views.OptOutConfirm()
     view.object = factories.OptOutFactory(pk=1, secret='7ebc5d464a6485e4b64f', email='*****@*****.**')
     url = view.get_success_url()
     self.assertEqual('/mocked_goodbye/1/7ebc5d464a6485e4b64f/[email protected]/', url)
Exemplo n.º 6
0
 def test_save(self):
     item = factories.OptOutFactory()
     url = resolve_url("django_opt_out:OptOutUpdate", item.pk, item.secret, item.email)
     response = test.Client().post(url, data={'email': item.email})
     self.assertNoFormErrors(response)
     self.assertRedirects(response, resolve_url("django_opt_out:OptOutSuccess", item.pk, item.secret, item.email))
Exemplo n.º 7
0
 def test_authorized(self):
     item = factories.OptOutFactory()
     url = resolve_url("django_opt_out:OptOutUpdate", item.pk, item.secret, item.email)
     response = test.Client().get(url)
     self.assertEqual(200, response.status_code)
     self.assertNoFormErrors(response)
Exemplo n.º 8
0
 def test_forbidden_bad_email(self):
     item = factories.OptOutFactory()
     url = resolve_url("django_opt_out:OptOutUpdate", item.pk, item.secret, 'a' + item.email)
     response = test.Client().get(url)
     self.assertEqual(403, response.status_code)