Coverage for /pythoncovmergedfiles/medio/medio/src/airflow/tests/providers/microsoft/azure/sensors/test_azure_cosmos.py: 0%
23 statements
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
« prev ^ index » next coverage.py v7.0.1, created at 2022-12-25 06:11 +0000
1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements. See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership. The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License. You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied. See the License for the
15# specific language governing permissions and limitations
16# under the License.
17from __future__ import annotations
19from unittest import mock
21from airflow.providers.microsoft.azure.sensors.cosmos import AzureCosmosDocumentSensor
23DB_NAME = "test-db-name"
24COLLECTION_NAME = "test-db-collection-name"
25DOCUMENT_ID = "test-document-id"
28class TestAzureCosmosSensor:
29 @mock.patch("airflow.providers.microsoft.azure.sensors.cosmos.AzureCosmosDBHook")
30 def test_should_call_hook_with_args(self, mock_hook):
31 mock_instance = mock_hook.return_value
32 mock_instance.get_document.return_value = True # Indicate document returned
33 sensor = AzureCosmosDocumentSensor(
34 task_id="test-task-1",
35 database_name=DB_NAME,
36 collection_name=COLLECTION_NAME,
37 document_id=DOCUMENT_ID,
38 )
39 result = sensor.poke(None)
40 mock_instance.get_document.assert_called_once_with(DOCUMENT_ID, DB_NAME, COLLECTION_NAME)
41 assert result is True
43 @mock.patch("airflow.providers.microsoft.azure.sensors.cosmos.AzureCosmosDBHook")
44 def test_should_return_false_on_no_document(self, mock_hook):
45 mock_instance = mock_hook.return_value
46 mock_instance.get_document.return_value = None # Indicate document not returned
47 sensor = AzureCosmosDocumentSensor(
48 task_id="test-task-2",
49 database_name=DB_NAME,
50 collection_name=COLLECTION_NAME,
51 document_id=DOCUMENT_ID,
52 )
53 result = sensor.poke(None)
54 mock_instance.get_document.assert_called_once_with(DOCUMENT_ID, DB_NAME, COLLECTION_NAME)
55 assert result is False