Exemplo n.º 1
0
    def test_error_mail_sent_with_object_error(self, mock_mailer_mail_recipient):

        context, harvest_source, harvest_job = self._create_harvest_source_and_job_if_not_existing()

        data_dict = {
            'guid': 'guid',
            'content': 'content',
            'job_id': harvest_job['id'],
            'extras': {'a key': 'a value'},
            'source_id': harvest_source['id']
        }
        harvest_object = toolkit.get_action('harvest_object_create')(
            context, data_dict)

        harvest_object_model = HarvestObject.get(harvest_object['id'])

        # create a HarvestObjectError
        msg = 'HarvestObjectError occured: %s' % harvest_job['id']
        harvest_object_error = HarvestObjectError(message=msg, object=harvest_object_model)
        harvest_object_error.save()

        status = toolkit.get_action('harvest_source_show_status')(context, {'id': harvest_source['id']})

        send_mail(
            context,
            harvest_source['id'],
            'test subject',
            'test body'
        )

        assert_equal(1, status['last_job']['stats']['errored'])
        assert mock_mailer_mail_recipient.called
Exemplo n.º 2
0
    def test_mail_sent(self, mock_mailer_mail_recipient):
        context, harvest_source, job = \
            self._create_harvest_source_and_job_if_not_existing()

        send_mail(
            context,
            harvest_source['id'],
            'test subject',
            'test body'
        )

        assert mock_mailer_mail_recipient.called
Exemplo n.º 3
0
    def test_error_mail_not_sent(self, mock_mailer_mail_recipient):
        context, harvest_source, job = \
            self._create_harvest_source_and_job_if_not_existing()
        status = toolkit.get_action('harvest_source_show_status')(
            context, {'id': harvest_source['id']})

        send_mail(
            context,
            harvest_source['id'],
            'test subject',
            'test body'
        )

        assert_equal(0, status['last_job']['stats']['errored'])
        assert mock_mailer_mail_recipient.not_called
Exemplo n.º 4
0
    def test_error_mail_sent(self, mock_mailer_mail_recipient):
        context, harvest_source, job = self._create_harvest_source_and_job_if_not_existing()

        # create a HarvestGatherError
        job_model = HarvestJob.get(job['id'])
        msg = 'System error - No harvester could be found for source type %s' % job_model.source.type
        err = HarvestGatherError(message=msg, job=job_model)
        err.save()

        status = toolkit.get_action('harvest_source_show_status')(context, {'id': harvest_source['id']})

        send_mail(
            context,
            harvest_source['id'],
            'test subject',
            'test body'
        )

        assert_equal(1, status['last_job']['stats']['errored'])
        assert mock_mailer_mail_recipient.called