-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Maxim Mityutko <[email protected]>
- Loading branch information
1 parent
2b70616
commit 144de7a
Showing
2 changed files
with
81 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import pytest | ||
from requests.exceptions import HTTPError | ||
from requests_mock.mocker import Mocker as RequestsMocker | ||
|
||
from brickflow_plugins.airflow.operators.external_tasks import AutosysSensor | ||
|
||
|
||
class TestAutosysSensor: | ||
@pytest.fixture(autouse=True, name="api", scope="class") | ||
def mock_api(self): | ||
rm = RequestsMocker() | ||
rm.register_uri( | ||
method="GET", | ||
url="https://42.autosys.my-org.com/foo", | ||
response_list=[ | ||
# Test 1: Success | ||
{ | ||
"json": {"status": "SU", "lastEndUTC": "2024-01-01T00:55:00Z"}, | ||
"status_code": int(200), | ||
}, | ||
# Test 2: Raise Error | ||
{ | ||
"json": {}, | ||
"status_code": int(404), | ||
}, | ||
# Test 3: Poke 4 times until success | ||
{ | ||
"json": {"status": "FA", "lastEndUTC": "2024-01-01T00:55:00Z"}, | ||
"status_code": int(200), | ||
}, | ||
{ | ||
"json": {"status": "UNK", "lastEndUTC": None}, | ||
"status_code": int(200), | ||
}, | ||
{ | ||
"json": {"status": "UNK", "lastEndUTC": ""}, | ||
"status_code": int(200), | ||
}, | ||
{ | ||
"json": {"status": "SU", "lastEndUTC": "2024-01-01T01:55:00Z"}, | ||
"status_code": int(200), | ||
}, | ||
], | ||
) | ||
yield rm | ||
|
||
@pytest.fixture() | ||
def sensor(self): | ||
yield AutosysSensor( | ||
task_id="test", | ||
url="https://42.autosys.my-org.com/", | ||
job_name="foo", | ||
poke_interval=1, | ||
time_delta={"hours": 1}, | ||
) | ||
|
||
def test_success(self, api, caplog, sensor): | ||
with api: | ||
sensor.poke(context={"execution_date": "2024-01-01T01:00:00Z"}) | ||
assert caplog.text.count("Poking again") == 0 | ||
assert "Success criteria met. Exiting" in caplog.text | ||
|
||
def test_non_200(self, api, sensor): | ||
with pytest.raises(HTTPError): | ||
with api: | ||
sensor.poke(context={"execution_date": "2024-01-01T01:00:00Z"}) | ||
|
||
def test_poking(self, api, caplog, sensor): | ||
with api: | ||
sensor.poke(context={"execution_date": "2024-01-01T02:00:00Z"}) | ||
assert caplog.text.count("Poking again") == 3 | ||
assert "Success criteria met. Exiting" in caplog.text |