Exemplo n.º 1
0
    def test_on_work_order_dispatched_no_drs_study_code(self, mocked_notify):
        drs_study_code = 'nil'
        message = self.create_fake_generic_work_order_message(
            EVENT_WO_DISPATCHED, drs_study_code)
        rule = Rule(env='test', config=config, message=message)
        rule.check_rules()
        self.assertIsInstance(mocked_notify, Notify)

        subject = "{0} {1} {2} [Data release:{3}]".format(
            SBJ_PREFIX_WO, message.metadata['work_order_id'], 'Dispatched',
            message.notifier_info['drs_study_code'])

        data = {
            'user_identifier': '*****@*****.**',
            'link':
            self._generate_wo_link(message.notifier_info['work_plan_id']),
            'work_order_status': 'dispatched',
            'work_order_id': message.metadata['work_order_id']
        }

        mocked_notify.return_value.send_email.assert_called_once_with(
            subject=subject,
            from_address=config.email.from_address,
            template='wo_event',
            to=['*****@*****.**'],
            data=data)
Exemplo n.º 2
0
    def test_common_manifest_called(self, mocked_notify):
        message = self.create_fake_generic_manifest_message(EVENT_MAN_RECEIVED)
        rule = Rule(env='test', config=config, message=message)
        rule._common_manifest = Mock()
        rule._common_manifest.return_value = [], {}
        rule.check_rules()

        rule._common_manifest.assert_called_once()
Exemplo n.º 3
0
    def test_common_work_order_called(self, mocked_notify):
        message = self.create_fake_generic_work_order_message(
            EVENT_WO_DISPATCHED, 1234)
        rule = Rule(env='test', config=config, message=message)
        rule._common_work_order = Mock()
        rule._common_work_order.return_value = [], {}
        rule.check_rules()

        rule._common_work_order.assert_called_once()
Exemplo n.º 4
0
    def test_manifest_received_triggered(self):
        message = self.create_fake_generic_manifest_message(EVENT_MAN_RECEIVED)
        rule = Rule(env='test', config='test', message=message)

        rule._on_manifest_create = Mock()
        rule._on_manifest_received = Mock()
        rule._on_work_order_event = Mock()
        rule._on_catalogue_new = Mock()
        rule._on_catalogue_processed = Mock()
        rule._on_catalogue_rejected = Mock()

        rule.check_rules()

        rule._on_manifest_create.assert_not_called()
        rule._on_manifest_received.assert_called_once()
        rule._on_work_order_event.assert_not_called()
        rule._on_catalogue_new.assert_not_called()
        rule._on_catalogue_processed.assert_not_called()
        rule._on_catalogue_rejected.assert_not_called()
Exemplo n.º 5
0
    def test_on_manifest_received(self, mocked_notify):
        message = self.create_fake_generic_manifest_message(EVENT_MAN_RECEIVED)
        rule = Rule(env='test', config=config, message=message)
        rule.check_rules()
        self.assertIsInstance(mocked_notify, Notify)
        subject = SBJ_MAN_RECEIVED + ' ' + str(message.metadata['manifest_id'])

        data = {
            'manifest_id': message.metadata['manifest_id'],
            'link':
            self._generate_manifest_link(message.metadata['manifest_id'])
        }

        mocked_notify.return_value.send_email.assert_called_once_with(
            subject=subject,
            from_address=config.email.from_address,
            template='manifest_received',
            to=['*****@*****.**', '*****@*****.**'],
            data=data)
Exemplo n.º 6
0
    def test_on_manifest_create_with_hmdmc(self, mocked_notify):
        message = self.FakeMessage(event_type=EVENT_MAN_CREATED,
                                   timestamp=datetime.now().isoformat(),
                                   user_identifier='*****@*****.**',
                                   metadata={
                                       'sample_custodian': '*****@*****.**',
                                       'manifest_id': 123,
                                       'hmdmc': 'abc321'
                                   },
                                   notifier_info={})

        rule = Rule(env='test', config=config, message=message)
        rule.check_rules()

        self.assertIsInstance(mocked_notify, Notify)
        self.assertEqual(mocked_notify.return_value.send_email.call_count, 2)

        exp1 = call(data={
            'hmdmc_list': 'abc321',
            'manifest_id': 123,
            'link':
            'http://aker.localhost:80/reception/material_submissions/123',
            'user_identifier': '*****@*****.**'
        },
                    from_address=u'*****@*****.**',
                    subject='Aker | Manifest Created 123',
                    template='manifest_created',
                    to=['*****@*****.**', '*****@*****.**'])

        exp2 = call(data={
            'hmdmc_list': 'abc321',
            'manifest_id': 123,
            'link':
            'http://aker.localhost:80/reception/material_submissions/123',
            'user_identifier': '*****@*****.**'
        },
                    from_address=u'*****@*****.**',
                    subject='Aker | Manifest Created with HMDMC 123',
                    template='manifest_created_hmdmc',
                    to=[u'*****@*****.**'])

        mocked_notify.return_value.send_email.assert_has_calls([exp1, exp2],
                                                               any_order=True)
Exemplo n.º 7
0
    def test_work_order_concluded_event_triggered(self):
        drs_study_code = 1234
        message = self.create_fake_generic_work_order_message(
            EVENT_WO_CONCLUDED, drs_study_code)
        rule = Rule(env='test', config='test', message=message)

        rule._on_manifest_create = Mock()
        rule._on_manifest_received = Mock()
        rule._on_work_order_event = Mock()
        rule._on_catalogue_new = Mock()
        rule._on_catalogue_processed = Mock()
        rule._on_catalogue_rejected = Mock()

        rule.check_rules()

        rule._on_manifest_create.assert_not_called()
        rule._on_manifest_received.assert_not_called()
        rule._on_work_order_event.assert_called_once()
        rule._on_catalogue_new.assert_not_called()
        rule._on_catalogue_processed.assert_not_called()
        rule._on_catalogue_rejected.assert_not_called()