Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/airflow/providers/microsoft/azure/sensors/cosmos.py: 0%

18 statements  

« prev     ^ index     » next       coverage.py v7.0.1, created at 2022-12-25 06:11 +0000

1# 

2# Licensed to the Apache Software Foundation (ASF) under one 

3# or more contributor license agreements. See the NOTICE file 

4# distributed with this work for additional information 

5# regarding copyright ownership. The ASF licenses this file 

6# to you under the Apache License, Version 2.0 (the 

7# "License"); you may not use this file except in compliance 

8# with the License. You may obtain a copy of the License at 

9# 

10# http://www.apache.org/licenses/LICENSE-2.0 

11# 

12# Unless required by applicable law or agreed to in writing, 

13# software distributed under the License is distributed on an 

14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 

15# KIND, either express or implied. See the License for the 

16# specific language governing permissions and limitations 

17# under the License. 

18from __future__ import annotations 

19 

20from typing import TYPE_CHECKING, Sequence 

21 

22from airflow.providers.microsoft.azure.hooks.cosmos import AzureCosmosDBHook 

23from airflow.sensors.base import BaseSensorOperator 

24 

25if TYPE_CHECKING: 

26 from airflow.utils.context import Context 

27 

28 

29class AzureCosmosDocumentSensor(BaseSensorOperator): 

30 """ 

31 Checks for the existence of a document which 

32 matches the given query in CosmosDB. Example: 

33 

34 .. code-block:: 

35 

36 azure_cosmos_sensor = AzureCosmosDocumentSensor( 

37 database_name="somedatabase_name", 

38 collection_name="somecollection_name", 

39 document_id="unique-doc-id", 

40 azure_cosmos_conn_id="azure_cosmos_default", 

41 task_id="azure_cosmos_sensor", 

42 ) 

43 

44 :param database_name: Target CosmosDB database_name. 

45 :param collection_name: Target CosmosDB collection_name. 

46 :param document_id: The ID of the target document. 

47 :param azure_cosmos_conn_id: Reference to the 

48 :ref:`Azure CosmosDB connection<howto/connection:azure_cosmos>`. 

49 """ 

50 

51 template_fields: Sequence[str] = ("database_name", "collection_name", "document_id") 

52 

53 def __init__( 

54 self, 

55 *, 

56 database_name: str, 

57 collection_name: str, 

58 document_id: str, 

59 azure_cosmos_conn_id: str = "azure_cosmos_default", 

60 **kwargs, 

61 ) -> None: 

62 super().__init__(**kwargs) 

63 self.azure_cosmos_conn_id = azure_cosmos_conn_id 

64 self.database_name = database_name 

65 self.collection_name = collection_name 

66 self.document_id = document_id 

67 

68 def poke(self, context: Context) -> bool: 

69 self.log.info("*** Entering poke") 

70 hook = AzureCosmosDBHook(self.azure_cosmos_conn_id) 

71 return hook.get_document(self.document_id, self.database_name, self.collection_name) is not None