12345678910111213141516171819202122232425262728293031 |
- def test_upsert_document(self, mock_cosmos):
- test_id = str(uuid.uuid4())
- # fmt: off
- (mock_cosmos
- .return_value
- .get_database_client
- .return_value
- .get_container_client
- .return_value
- .upsert_item
- .return_value) = {'id': test_id}
- # fmt: on
- hook = AzureCosmosDBHook(azure_cosmos_conn_id='azure_cosmos_test_key_id')
- returned_item = hook.upsert_document(
- {'data1': 'somedata'},
- database_name=self.test_database_name,
- collection_name=self.test_collection_name,
- document_id=test_id,
- )
- expected_calls = [
- mock.call()
- .get_database_client('test_database_name')
- .get_container_client('test_collection_name')
- .upsert_item({'data1': 'somedata', 'id': test_id})
- ]
- mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key})
- mock_cosmos.assert_has_calls(expected_calls)
- logging.getLogger().info(returned_item)
- assert returned_item['id'] == test_id
|