예제 #1
0
    def test_post_with_valid_data_does_not_create_action_instance_if_exception_raised(
            self):
        scenario = self._create_scenario(email_args=dict(
            subject=u'Subject',
            text=u'Content',
            processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.txt',
                                              content=u'content',
                                              content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email,
                                              name=u'filename.html',
                                              content=u'<p>content</p>',
                                              content_type=u'text/html')
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(scenario.branch.action_set) as action_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(
                    url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
예제 #2
0
    def test_post_request_with_valid_data_rolls_back_if_exception_raised(self):
        def receiver(*args, **kwargs):
            self._create_message()

        with self._overrides(MANDRILL_WEBHOOK_URL=u'https://testhost/', MANDRILL_WEBHOOK_KEYS=[u'testkey']):
            webhook_event.connect(receiver)

            # No exceptions, data commited
            with created_instances(Message.objects) as msg_set:
                self.client.post(self._webhook_url(), secure=True,
                        data={u'mandrill_events': json.dumps([
                            {u'event': u'click', u'_id': u'remote-1'},
                            ])},
                        HTTP_X_MANDRILL_SIGNATURE=u'phOye9ZN3XunJ8SG7R9AT6KhpUo=')
            self.assertTrue(msg_set.exists())

            # With exception, data rolled back
            with created_instances(Message.objects) as msg_set:
                with patch_with_exception(u'poleno.mail.transports.mandrill.views.HttpResponse'):
                    self.client.post(self._webhook_url(), secure=True,
                            data={u'mandrill_events': json.dumps([
                                {u'event': u'click', u'_id': u'remote-1'},
                                ])},
                            HTTP_X_MANDRILL_SIGNATURE=u'phOye9ZN3XunJ8SG7R9AT6KhpUo=')
            self.assertFalse(msg_set.exists())
예제 #3
0
 def test_post_with_submit_button_and_valid_data_does_not_delete_draft_if_exception_raised(self):
     draft = self._create_inforequest_draft(applicant=self.user1)
     data = self._create_post_data(button=u'submit')
     self._login_user(self.user1)
     with patch_with_exception(u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'):
         response = self.client.post(reverse(u'inforequests:create_from_draft', args=(draft.pk,)), data)
     self.assertTrue(InforequestDraft.objects.filter(pk=draft.pk).exists())
예제 #4
0
    def test_post_with_draft_button_and_valid_data_does_not_update_existing_draft_instance_if_exception_raised(
            self):
        self._login_user(self.user1)
        obligee = self._create_obligee(name=u'New Obligee')
        attachment1 = self._create_attachment(
            generic_object=self._get_session())
        attachment2 = self._create_attachment(
            generic_object=self._get_session())
        draft = self._create_inforequest_draft(applicant=self.user1,
                                               obligee=self.obligee1,
                                               subject=[u'Old Subject'],
                                               content=[u'Old Content'])
        attachment3 = self._create_attachment(generic_object=draft)
        data = self._create_post_data(button=u'draft',
                                      obligee=u'New Obligee',
                                      subject=[u'New Subject'],
                                      content=[u'New Content'],
                                      attachments=u'%s,%s' %
                                      (attachment1.pk, attachment3.pk))

        with created_instances(
                InforequestDraft.objects) as inforequestdraft_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'
            ):
                response = self.client.post(
                    reverse(u'inforequests:create_from_draft',
                            args=(draft.pk, )), data)

        self.assertFalse(inforequestdraft_set.exists())
        draft = InforequestDraft.objects.get(pk=draft.pk)
        self.assertEqual(draft.subject, [u'Old Subject'])
예제 #5
0
    def test_post_with_submit_button_and_valid_data_does_not_send_inforequest_email_if_exception_raised(self):
        user = self._create_user(first_name=u'John', last_name=u'Smith')
        data = self._create_post_data(button=u'submit')

        self._login_user(user)
        with created_instances(Message.objects) as message_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'):
                response = self.client.post(reverse(u'inforequests:create'), data)
        self.assertFalse(message_set.exists())
예제 #6
0
    def test_post_with_default_button_and_valid_data_does_not_delete_draft_if_exception_raised(self):
        scenario = self._create_scenario(draft_args=dict())
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
            response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        self.assertTrue(ActionDraft.objects.filter(pk=scenario.draft.pk).exists())
예제 #7
0
    def test_post_with_default_button_and_valid_data_does_not_create_action_if_exception_raised(self):
        scenario = self._create_scenario()
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(scenario.branch.action_set) as action_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())
    def test_post_does_not_mark_email_as_unknown_if_exception_raised(self):
        scenario = self._create_scenario()
        data = self._create_post_data()
        url = self._create_url(scenario)

        self._login_user()
        with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
            response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
예제 #9
0
 def test_post_with_submit_button_and_valid_data_does_not_delete_draft_if_exception_raised(
         self):
     draft = self._create_inforequest_draft(applicant=self.user1)
     data = self._create_post_data(button=u'submit')
     self._login_user(self.user1)
     with patch_with_exception(
             u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'):
         response = self.client.post(
             reverse(u'inforequests:create_from_draft', args=(draft.pk, )),
             data)
     self.assertTrue(InforequestDraft.objects.filter(pk=draft.pk).exists())
예제 #10
0
    def test_post_with_submit_button_and_valid_data_does_not_send_inforequest_email_if_exception_raised(
            self):
        user = self._create_user(first_name=u'John', last_name=u'Smith')
        data = self._create_post_data(button=u'submit')

        self._login_user(user)
        with created_instances(Message.objects) as message_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'
            ):
                response = self.client.post(reverse(u'inforequests:create'),
                                            data)
        self.assertFalse(message_set.exists())
예제 #11
0
    def test_post_with_valid_data_does_not_save_deadline_extension_if_exception_raised(self):
        scenario = self._create_scenario(created=u'2014-10-01', now=u'2014-10-16',
                inforequest_scenario=[(u'request', dict(deadline=10))])
        data = self._create_post_data(extension=7)
        url = self._create_url(scenario)

        self._login_user()
        with mock.patch(u'chcemvediet.apps.inforequests.models.action.workdays.between', side_effect=lambda a,b: (b-a).days):
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        action = Action.objects.get(pk=scenario.action.pk)
        self.assertIsNone(action.extension)
예제 #12
0
    def test_post_does_not_mark_email_as_unrelated_if_exception_raised(self):
        scenario = self._create_scenario()
        data = self._create_post_data()
        url = self._create_url(scenario)

        self._login_user()
        with patch_with_exception(
                u'chcemvediet.apps.inforequests.views.JsonResponse'):
            response = self.client.post(
                url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
예제 #13
0
    def test_post_with_default_button_and_valid_data_does_not_create_action_if_exception_raised(
            self):
        scenario = self._create_scenario()
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(scenario.branch.action_set) as action_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(
                    url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())
예제 #14
0
    def test_post_with_submit_button_and_valid_data_does_not_create_inforequest_if_exception_raised(self):
        self._login_user(self.user1)
        obligee = self._create_obligee(name=u'Obligee')
        attachment1 = self._create_attachment(generic_object=self._get_session())
        attachment2 = self._create_attachment(generic_object=self._get_session())
        data = self._create_post_data(button=u'submit', obligee=u'Obligee',
                subject=[u'Subject'], content=[u'Content'],
                attachments=u'%s,%s' % (attachment1.pk, attachment2.pk))

        with created_instances(Inforequest.objects) as inforequest_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'):
                response = self.client.post(reverse(u'inforequests:create'), data)
        self.assertFalse(inforequest_set.exists())
예제 #15
0
    def test_post_with_default_button_and_valid_data_does_not_delete_draft_if_exception_raised(
            self):
        scenario = self._create_scenario(draft_args=dict())
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with patch_with_exception(
                u'chcemvediet.apps.inforequests.views.JsonResponse'):
            response = self.client.post(
                url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        self.assertTrue(
            ActionDraft.objects.filter(pk=scenario.draft.pk).exists())
예제 #16
0
    def test_post_with_draft_button_and_valid_data_does_not_update_existing_draft_instance_if_exception_raised(self):
        scenario = self._create_scenario(draft_args=dict(branch=None))
        data = self._create_post_data(button=u'draft', branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(ActionDraft.objects) as actiondraft_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(actiondraft_set.exists())

        draft = ActionDraft.objects.get(pk=scenario.draft.pk)
        self.assertEqual(draft.inforequest, scenario.inforequest)
        self.assertIsNone(draft.branch)
예제 #17
0
    def test_post_with_valid_data_does_not_create_action_instance_if_exception_raised(self):
        scenario = self._create_scenario(email_args=dict(subject=u'Subject', text=u'Content', processed=utc_datetime_from_local(u'2010-10-05 00:33:00')))
        attachment1 = self._create_attachment(generic_object=scenario.email, name=u'filename.txt', content=u'content', content_type=u'text/plain')
        attachment2 = self._create_attachment(generic_object=scenario.email, name=u'filename.html', content=u'<p>content</p>', content_type=u'text/html')
        data = self._create_post_data(branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(scenario.branch.action_set) as action_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(action_set.exists())

        scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk)
        self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.UNDECIDED)
예제 #18
0
    def test_post_with_draft_button_and_valid_data_does_not_update_existing_draft_instance_if_exception_raised(
            self):
        scenario = self._create_scenario(draft_args=dict(branch=None))
        data = self._create_post_data(button=u'draft', branch=scenario.branch)
        url = self._create_url(scenario)

        self._login_user()
        with created_instances(ActionDraft.objects) as actiondraft_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(
                    url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')
        self.assertFalse(actiondraft_set.exists())

        draft = ActionDraft.objects.get(pk=scenario.draft.pk)
        self.assertEqual(draft.inforequest, scenario.inforequest)
        self.assertIsNone(draft.branch)
예제 #19
0
    def test_post_with_draft_button_and_valid_data_does_not_update_existing_draft_instance_if_exception_raised(self):
        self._login_user(self.user1)
        obligee = self._create_obligee(name=u'New Obligee')
        attachment1 = self._create_attachment(generic_object=self._get_session())
        attachment2 = self._create_attachment(generic_object=self._get_session())
        draft = self._create_inforequest_draft(applicant=self.user1, obligee=self.obligee1, subject=[u'Old Subject'], content=[u'Old Content'])
        attachment3 = self._create_attachment(generic_object=draft)
        data = self._create_post_data(button=u'draft', obligee=u'New Obligee',
                subject=[u'New Subject'], content=[u'New Content'],
                attachments=u'%s,%s' % (attachment1.pk, attachment3.pk))

        with created_instances(InforequestDraft.objects) as inforequestdraft_set:
            with patch_with_exception(u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'):
                response = self.client.post(reverse(u'inforequests:create_from_draft', args=(draft.pk,)), data)

        self.assertFalse(inforequestdraft_set.exists())
        draft = InforequestDraft.objects.get(pk=draft.pk)
        self.assertEqual(draft.subject, [u'Old Subject'])
예제 #20
0
    def test_post_request_with_valid_data_rolls_back_if_exception_raised(self):
        def receiver(*args, **kwargs):
            self._create_message()

        with self._overrides(MANDRILL_WEBHOOK_URL=u'https://testhost/',
                             MANDRILL_WEBHOOK_KEYS=[u'testkey']):
            webhook_event.connect(receiver)

            # No exceptions, data commited
            with created_instances(Message.objects) as msg_set:
                self.client.post(
                    self._webhook_url(),
                    secure=True,
                    data={
                        u'mandrill_events':
                        json.dumps([
                            {
                                u'event': u'click',
                                u'_id': u'remote-1'
                            },
                        ])
                    },
                    HTTP_X_MANDRILL_SIGNATURE=u'phOye9ZN3XunJ8SG7R9AT6KhpUo=')
            self.assertTrue(msg_set.exists())

            # With exception, data rolled back
            with created_instances(Message.objects) as msg_set:
                with patch_with_exception(
                        u'poleno.mail.transports.mandrill.views.HttpResponse'):
                    self.client.post(self._webhook_url(),
                                     secure=True,
                                     data={
                                         u'mandrill_events':
                                         json.dumps([
                                             {
                                                 u'event': u'click',
                                                 u'_id': u'remote-1'
                                             },
                                         ])
                                     },
                                     HTTP_X_MANDRILL_SIGNATURE=
                                     u'phOye9ZN3XunJ8SG7R9AT6KhpUo=')
            self.assertFalse(msg_set.exists())
    def test_post_with_valid_data_does_not_save_deadline_extension_if_exception_raised(
            self):
        scenario = self._create_scenario(created=u'2014-10-01',
                                         now=u'2014-10-16',
                                         inforequest_scenario=[
                                             (u'request', dict(deadline=10))
                                         ])
        data = self._create_post_data(extension=7)
        url = self._create_url(scenario)

        self._login_user()
        with mock.patch(
                u'chcemvediet.apps.inforequests.models.action.workdays.between',
                side_effect=lambda a, b: (b - a).days):
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.JsonResponse'):
                response = self.client.post(
                    url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest')

        action = Action.objects.get(pk=scenario.action.pk)
        self.assertIsNone(action.extension)
예제 #22
0
    def test_post_with_submit_button_and_valid_data_does_not_create_inforequest_if_exception_raised(
            self):
        self._login_user(self.user1)
        obligee = self._create_obligee(name=u'Obligee')
        attachment1 = self._create_attachment(
            generic_object=self._get_session())
        attachment2 = self._create_attachment(
            generic_object=self._get_session())
        data = self._create_post_data(button=u'submit',
                                      obligee=u'Obligee',
                                      subject=[u'Subject'],
                                      content=[u'Content'],
                                      attachments=u'%s,%s' %
                                      (attachment1.pk, attachment2.pk))

        with created_instances(Inforequest.objects) as inforequest_set:
            with patch_with_exception(
                    u'chcemvediet.apps.inforequests.views.HttpResponseRedirect'
            ):
                response = self.client.post(reverse(u'inforequests:create'),
                                            data)
        self.assertFalse(inforequest_set.exists())