def test_instance_tasks(mock_get_tasks_from_app_id, mock_instance_status, mock_add_slave_info, mock_add_executor_info): mock_request = mock.Mock(swagger_data={'task_id': '123', 'slave_hostname': 'host1'}) mock_instance_status.return_value = {'marathon': {'app_id': 'app1'}} mock_task_1 = mock.Mock() mock_task_2 = mock.Mock() mock_get_tasks_from_app_id.return_value = [mock_task_1, mock_task_2] ret = instance.instance_tasks(mock_request) assert not mock_add_slave_info.called assert not mock_add_executor_info.called mock_request = mock.Mock(swagger_data={'task_id': '123', 'slave_hostname': 'host1', 'verbose': True}) ret = instance.instance_tasks(mock_request) mock_add_executor_info.assert_has_calls([mock.call(mock_task_1), mock.call(mock_task_2)]) mock_add_slave_info.assert_has_calls([ mock.call(mock_add_executor_info.return_value), mock.call(mock_add_executor_info.return_value), ]) expected = [ mock_add_slave_info.return_value._Task__items, mock_add_slave_info.return_value._Task__items, ] def ids(l): return {id(x) for x in l} assert len(ret) == len(expected) and ids(expected) == ids(ret) mock_instance_status.return_value = {'chronos': {}} with raises(ApiFailure): ret = instance.instance_tasks(mock_request)
def test_instance_tasks( mock_get_tasks_from_app_id, mock_instance_status, mock_add_slave_info, mock_add_executor_info, ): mock_request = mock.Mock(swagger_data={ "task_id": "123", "slave_hostname": "host1" }) mock_instance_status.return_value = { "marathon": { "desired_app_id": "app1" } } mock_task_1 = mock.Mock() mock_task_2 = mock.Mock() mock_get_tasks_from_app_id.return_value = [mock_task_1, mock_task_2] ret = instance.instance_tasks(mock_request) assert not mock_add_slave_info.called assert not mock_add_executor_info.called mock_request = mock.Mock(swagger_data={ "task_id": "123", "slave_hostname": "host1", "verbose": True }) ret = instance.instance_tasks(mock_request) mock_add_executor_info.assert_has_calls( [mock.call(mock_task_1), mock.call(mock_task_2)]) mock_add_slave_info.assert_has_calls([ mock.call(mock_add_executor_info.return_value), mock.call(mock_add_executor_info.return_value), ]) expected = [ mock_add_slave_info.return_value._Task__items, mock_add_slave_info.return_value._Task__items, ] def ids(l): return {id(x) for x in l} assert len(ret) == len(expected) and ids(expected) == ids(ret)
def test_instance_tasks(mock_get_tasks_from_app_id, mock_instance_status, mock_add_slave_info, mock_add_executor_info): mock_request = mock.Mock(swagger_data={'task_id': '123', 'slave_hostname': 'host1'}) mock_instance_status.return_value = {'marathon': {'app_id': 'app1'}} mock_task_1 = mock.Mock() mock_task_2 = mock.Mock() mock_get_tasks_from_app_id.return_value = [mock_task_1, mock_task_2] ret = instance.instance_tasks(mock_request) assert not mock_add_slave_info.called assert not mock_add_executor_info.called mock_request = mock.Mock(swagger_data={'task_id': '123', 'slave_hostname': 'host1', 'verbose': True}) ret = instance.instance_tasks(mock_request) mock_add_executor_info.assert_has_calls([mock.call(mock_task_1), mock.call(mock_task_2)]) mock_add_slave_info.assert_has_calls([mock.call(mock_add_executor_info.return_value), mock.call(mock_add_executor_info.return_value)]) expected = [mock_add_slave_info.return_value._Task__items, mock_add_slave_info.return_value._Task__items] assert len(ret) == len(expected) and sorted(expected) == sorted(ret) mock_instance_status.return_value = {'chronos': {}} with raises(ApiFailure): ret = instance.instance_tasks(mock_request)