Пример #1
0
    def test_execute_with_messages_logs(self, aci_mock):
        events = [Event(message="test"), Event(message="messages")]
        expected_c_state1 = ContainerState(state='Running', exit_code=0, detail_status='test')
        expected_cg1 = make_mock_cg(expected_c_state1, events)
        expected_c_state2 = ContainerState(state='Terminated', exit_code=0, detail_status='test')
        expected_cg2 = make_mock_cg(expected_c_state2, events)

        aci_mock.return_value.get_state.side_effect = [expected_cg1, expected_cg2]
        aci_mock.return_value.get_logs.return_value = ["test", "logs"]
        aci_mock.return_value.exists.return_value = False

        aci = AzureContainerInstancesOperator(
            ci_conn_id=None,
            registry_conn_id=None,
            resource_group='resource-group',
            name='container-name',
            image='container-image',
            region='region',
            task_id='task',
        )
        aci.execute(None)

        self.assertEqual(aci_mock.return_value.create_or_update.call_count, 1)
        self.assertEqual(aci_mock.return_value.get_state.call_count, 2)
        self.assertEqual(aci_mock.return_value.get_logs.call_count, 2)

        self.assertEqual(aci_mock.return_value.delete.call_count, 1)
Пример #2
0
    def test_get_messages(self, get_instance_view_mock):
        expected_messages = ['test1', 'test2']
        events = [Event(message=m) for m in expected_messages]
        instance_view = {"events": events}
        named_instance = namedtuple("Events", instance_view.keys())(*instance_view.values())
        get_instance_view_mock.return_value = named_instance

        messages = self.testHook.get_messages('resource-group', 'test')

        self.assertSequenceEqual(messages, expected_messages)