def test_create_database(self, mock_cosmos): hook = AzureCosmosDBHook( azure_cosmos_conn_id='azure_cosmos_test_key_id') hook.create_database(self.test_database_name) expected_calls = [ mock.call().CreateDatabase({'id': self.test_database_name}) ] mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key}) mock_cosmos.assert_has_calls(expected_calls)
def execute(self, context: Dict[Any, Any]) -> None: # Create the hook hook = AzureCosmosDBHook(azure_cosmos_conn_id=self.azure_cosmos_conn_id) # Create the DB if it doesn't already exist if not hook.does_database_exist(self.database_name): hook.create_database(self.database_name) # Create the collection as well if not hook.does_collection_exist(self.collection_name, self.database_name): hook.create_collection(self.collection_name, self.database_name) # finally insert the document hook.upsert_document(self.document, self.database_name, self.collection_name)
def test_create_database_exception(self, mock_cosmos): hook = AzureCosmosDBHook( azure_cosmos_conn_id='azure_cosmos_test_key_id') with pytest.raises(AirflowException): hook.create_database(None)