1234567891011121314151617181920212223242526272829 |
- def test_insert_documents(self, mock_cosmos):
- test_id1 = str(uuid.uuid4())
- test_id2 = str(uuid.uuid4())
- test_id3 = str(uuid.uuid4())
- documents = [
- {'id': test_id1, 'data': 'data1'},
- {'id': test_id2, 'data': 'data2'},
- {'id': test_id3, 'data': 'data3'},
- ]
- hook = AzureCosmosDBHook(azure_cosmos_conn_id='azure_cosmos_test_key_id')
- returned_item = hook.insert_documents(documents)
- expected_calls = [
- mock.call()
- .get_database_client('test_database_name')
- .get_container_client('test_collection_name')
- .create_item({'data': 'data1', 'id': test_id1}),
- mock.call()
- .get_database_client('test_database_name')
- .get_container_client('test_collection_name')
- .create_item({'data': 'data2', 'id': test_id2}),
- mock.call()
- .get_database_client('test_database_name')
- .get_container_client('test_collection_name')
- .create_item({'data': 'data3', 'id': test_id3}),
- ]
- logging.getLogger().info(returned_item)
- mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key})
- mock_cosmos.assert_has_calls(expected_calls, any_order=True)
|