test.py
def convert_string_to_object(string):
...
...
return object
def add_data(string):
es = get_connect_elasticsearch()
object = convert_string_to_object(string)
es.index(index='test_index', object)
我正在尝试模拟是否在上述es.index()
函数中将正确的参数传递给add_data()
test.py
这是我到目前为止所取得的成就。我究竟做错了什么?还是有更好的方法来做到这一点?
def test_that_correct_argument_is_passed_to_indexing(self):
get_connect_elasticsearch = MagicMock()
mock_string = "bla:bla:bla"
add_data(mock_string)
expected_object = {...}
get_connect_elasticsearch().index.assert_called_with('test_index', expected_object)