|
| 1 | +import pytest |
| 2 | +from uipath.core.triggers import ( |
| 3 | + UIPATH_METADATA_KEY, |
| 4 | + UiPathResumeTriggerName, |
| 5 | + UiPathResumeTriggerType, |
| 6 | +) |
| 7 | + |
| 8 | +from uipath.platform.common import ( |
| 9 | + UiPathResumeMetadata, |
| 10 | + UiPathTimeoutError, |
| 11 | + assert_no_timeout, |
| 12 | + get_resume_metadata, |
| 13 | + is_timeout, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def test_is_timeout_detects_timeout_metadata() -> None: |
| 18 | + value = { |
| 19 | + UIPATH_METADATA_KEY: { |
| 20 | + "kind": "timeout", |
| 21 | + "triggerType": "Timer", |
| 22 | + "triggerName": "Timer", |
| 23 | + }, |
| 24 | + "value": None, |
| 25 | + } |
| 26 | + |
| 27 | + assert is_timeout(value) is True |
| 28 | + |
| 29 | + |
| 30 | +def test_get_resume_metadata_returns_typed_metadata() -> None: |
| 31 | + value = { |
| 32 | + UIPATH_METADATA_KEY: { |
| 33 | + "kind": "timeout", |
| 34 | + "triggerType": "Timer", |
| 35 | + "triggerName": "Timer", |
| 36 | + }, |
| 37 | + "resumeTime": "2026-07-07T12:00:00Z", |
| 38 | + } |
| 39 | + |
| 40 | + metadata = get_resume_metadata(value) |
| 41 | + |
| 42 | + assert isinstance(metadata, UiPathResumeMetadata) |
| 43 | + assert metadata.kind == "timeout" |
| 44 | + assert metadata.trigger_type == UiPathResumeTriggerType.TIMER |
| 45 | + assert metadata.trigger_name == UiPathResumeTriggerName.TIMER |
| 46 | + |
| 47 | + |
| 48 | +def test_get_resume_metadata_returns_none_without_metadata() -> None: |
| 49 | + assert get_resume_metadata({"result": "done"}) is None |
| 50 | + assert get_resume_metadata("done") is None |
| 51 | + |
| 52 | + |
| 53 | +def test_get_resume_metadata_returns_none_for_invalid_metadata() -> None: |
| 54 | + value = { |
| 55 | + UIPATH_METADATA_KEY: { |
| 56 | + "triggerType": "NotARealTrigger", |
| 57 | + "triggerName": "Timer", |
| 58 | + }, |
| 59 | + } |
| 60 | + |
| 61 | + assert get_resume_metadata(value) is None |
| 62 | + |
| 63 | + |
| 64 | +def test_is_timeout_ignores_plain_timer_metadata() -> None: |
| 65 | + value = { |
| 66 | + UIPATH_METADATA_KEY: { |
| 67 | + "triggerType": "Timer", |
| 68 | + "triggerName": "Timer", |
| 69 | + }, |
| 70 | + "resumeTime": "2026-07-07T12:00:00Z", |
| 71 | + } |
| 72 | + |
| 73 | + assert is_timeout(value) is False |
| 74 | + |
| 75 | + |
| 76 | +def test_is_timeout_ignores_user_timed_out_fields() -> None: |
| 77 | + assert is_timeout({"timedOut": True}) is False |
| 78 | + assert is_timeout("timeout") is False |
| 79 | + |
| 80 | + |
| 81 | +def test_assert_no_timeout_returns_original_value() -> None: |
| 82 | + value = {"result": "done"} |
| 83 | + |
| 84 | + assert assert_no_timeout(value) is value |
| 85 | + |
| 86 | + |
| 87 | +def test_assert_no_timeout_raises_with_resume_value() -> None: |
| 88 | + value = { |
| 89 | + UIPATH_METADATA_KEY: {"kind": "timeout"}, |
| 90 | + "value": {"jobKey": "job-1"}, |
| 91 | + } |
| 92 | + |
| 93 | + with pytest.raises(UiPathTimeoutError) as exc_info: |
| 94 | + assert_no_timeout(value) |
| 95 | + |
| 96 | + assert exc_info.value.value is value |
0 commit comments