test_azure_cosmos_8.py 941 B

123456789101112131415161718192021222324
  1. def test_upsert_document_default(self, mock_cosmos):
  2. test_id = str(uuid.uuid4())
  3. # fmt: off
  4. (mock_cosmos
  5. .return_value
  6. .get_database_client
  7. .return_value
  8. .get_container_client
  9. .return_value
  10. .upsert_item
  11. .return_value) = {'id': test_id}
  12. # fmt: on
  13. hook = AzureCosmosDBHook(azure_cosmos_conn_id='azure_cosmos_test_key_id')
  14. returned_item = hook.upsert_document({'id': test_id})
  15. expected_calls = [
  16. mock.call()
  17. .get_database_client('test_database_name')
  18. .get_container_client('test_collection_name')
  19. .upsert_item({'id': test_id})
  20. ]
  21. mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key})
  22. mock_cosmos.assert_has_calls(expected_calls)
  23. logging.getLogger().info(returned_item)
  24. assert returned_item['id'] == test_id