test_azure_cosmos_10.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. def test_insert_documents(self, mock_cosmos):
  2. test_id1 = str(uuid.uuid4())
  3. test_id2 = str(uuid.uuid4())
  4. test_id3 = str(uuid.uuid4())
  5. documents = [
  6. {'id': test_id1, 'data': 'data1'},
  7. {'id': test_id2, 'data': 'data2'},
  8. {'id': test_id3, 'data': 'data3'},
  9. ]
  10. hook = AzureCosmosDBHook(azure_cosmos_conn_id='azure_cosmos_test_key_id')
  11. returned_item = hook.insert_documents(documents)
  12. expected_calls = [
  13. mock.call()
  14. .get_database_client('test_database_name')
  15. .get_container_client('test_collection_name')
  16. .create_item({'data': 'data1', 'id': test_id1}),
  17. mock.call()
  18. .get_database_client('test_database_name')
  19. .get_container_client('test_collection_name')
  20. .create_item({'data': 'data2', 'id': test_id2}),
  21. mock.call()
  22. .get_database_client('test_database_name')
  23. .get_container_client('test_collection_name')
  24. .create_item({'data': 'data3', 'id': test_id3}),
  25. ]
  26. logging.getLogger().info(returned_item)
  27. mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key})
  28. mock_cosmos.assert_has_calls(expected_calls, any_order=True)