Exemplo n.º 1
0
 def test_create_container_default(self, mock_cosmos):
     hook = AzureCosmosDBHook(azure_cosmos_conn_id='azure_cosmos_test_key_id')
     hook.create_collection(self.test_collection_name)
     expected_calls = [mock.call().CreateContainer(
         'dbs/test_database_default',
         {'id': self.test_collection_name})]
     mock_cosmos.assert_any_call(self.test_end_point, {'masterKey': self.test_master_key})
     mock_cosmos.assert_has_calls(expected_calls)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def test_create_container_exception(self, mock_cosmos):
     hook = AzureCosmosDBHook(
         azure_cosmos_conn_id='azure_cosmos_test_key_id')
     with pytest.raises(AirflowException):
         hook.create_collection(None)