Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
[NO-TICKET] Remove bad tests (#5159)
Aaron Perez640cdeb7882c
diff --git a/tests/unit/test_local_schedule_runner.py b/tests/unit/test_local_schedule_runner.pydeleted file mode 100644index bd6ed6a79..000000000--- a/tests/unit/test_local_schedule_runner.py+++ /dev/null@@ -1,143 +0,0 @@-import importlib.util-from datetime import UTC, datetime, timedelta-from types import SimpleNamespace-from unittest.mock import AsyncMock, patch--import pytest--from skyvern.forge.sdk.workflow.schedules import compute_previous_fire_time--_skip_no_local_schedules = pytest.mark.skipif(- importlib.util.find_spec("scripts.run_local_schedules") is None,- reason="scripts.run_local_schedules not available (cloud-only)",-)---class TestComputePreviousFireTime:- def test_returns_past_time(self) -> None:- """compute_previous_fire_time should return a time before now."""- result = compute_previous_fire_time("*/5 * * * *", "UTC")- assert result < datetime.now(UTC)-- def test_returns_utc(self) -> None:- result = compute_previous_fire_time("0 * * * *", "UTC")- assert result.tzinfo is not None-- def test_respects_timezone(self) -> None:- """Results for different timezones may differ."""- utc_result = compute_previous_fire_time("0 0 * * *", "UTC")- tokyo_result = compute_previous_fire_time("0 0 * * *", "Asia/Tokyo")- # Both are valid datetimes in UTC; they differ because midnight- # in Tokyo and midnight in UTC are 9 hours apart.- assert utc_result != tokyo_result-- def test_every_5_min_within_5_minutes(self) -> None:- """For a */5 cron, the previous fire time should be within 5 minutes of now."""- result = compute_previous_fire_time("*/5 * * * *", "UTC")- now = datetime.now(UTC)- assert now - result <= timedelta(minutes=5)---@_skip_no_local_schedules-class TestShouldFire:- @pytest.mark.asyncio- async def test_true_when_no_recent_run(self) -> None:- """should_fire returns True when has_schedule_fired_since returns False."""- schedule = SimpleNamespace(- workflow_schedule_id="ws_test",- cron_expression="*/5 * * * *",- timezone="UTC",- )- fake_db = SimpleNamespace(- has_schedule_fired_since=AsyncMock(return_value=False),- )-- with patch("scripts.run_local_schedules.app") as mock_app:- mock_app.DATABASE = fake_db- from scripts.run_local_schedules import should_fire-- result = await should_fire(schedule)-- assert result is True- fake_db.has_schedule_fired_since.assert_called_once()-- @pytest.mark.asyncio- async def test_false_when_run_exists_in_window(self) -> None:- """should_fire returns False when a run already exists for this window."""- schedule = SimpleNamespace(- workflow_schedule_id="ws_test",- cron_expression="*/5 * * * *",- timezone="UTC",- )- fake_db = SimpleNamespace(- has_schedule_fired_since=AsyncMock(return_value=True),- )-- with patch("scripts.run_local_schedules.app") as mock_app:- mock_app.DATABASE = fake_db- from scripts.run_local_schedules import should_fire-- result = await should_fire(schedule)-- assert result is False---@_skip_no_local_schedules-class TestFireScheduleAuthCheck:- @pytest.mark.asyncio- async def test_skips_without_auth_token(self) -> None:- """fire_schedule raises RuntimeError when org has no valid auth token."""- schedule = SimpleNamespace(- workflow_schedule_id="ws_no_auth",- organization_id="org_no_auth",- workflow_permanent_id="wpid_no_auth",- cron_expression="*/5 * * * *",- timezone="UTC",- parameters=None,- )- fake_db = SimpleNamespace(- get_valid_org_auth_token=AsyncMock(return_value=None),- )-- with patch("scripts.run_local_schedules.app") as mock_app:- mock_app.DATABASE = fake_db- from scripts.run_local_schedules import fire_schedule-- with pytest.raises(RuntimeError, match="No valid auth token"):- await fire_schedule(schedule)-- fake_db.get_valid_org_auth_token.assert_called_once_with(- organization_id="org_no_auth",- token_type="api",- )---@_skip_no_local_schedules-class TestDryRun:- @pytest.mark.asyncio- async def test_dry_run_does_not_fire(self) -> None:- """poll_once with dry_run=True should not call fire_schedule."""- schedule = SimpleNamespace(- workflow_schedule_id="ws_dry",- workflow_permanent_id="wpid_dry",- cron_expression="*/5 * * * *",- timezone="UTC",- organization_id="org_dry",- parameters=None,- )- fake_db = SimpleNamespace(- get_all_enabled_schedules=AsyncMock(return_value=[schedule]),- has_schedule_fired_since=AsyncMock(return_value=False),- )-- with (- patch("scripts.run_local_schedules.app") as mock_app,- patch("scripts.run_local_schedules.fire_schedule") as mock_fire,- ):- mock_app.DATABASE = fake_db- from scripts.run_local_schedules import poll_once-- result = await poll_once(dry_run=True)-- assert result == []- mock_fire.assert_not_called()diff --git a/tests/unit/test_temporal_v2_workflow_activities.py b/tests/unit/test_temporal_v2_workflow_activities.pydeleted file mode 100644index f83b85f24..000000000--- a/tests/unit/test_temporal_v2_workflow_activities.py+++ /dev/null@@ -1,238 +0,0 @@-import importlib-import sys-from types import ModuleType, SimpleNamespace-from unittest.mock import AsyncMock--import pytest--from skyvern.forge.sdk.db.enums import WorkflowRunTriggerType-from skyvern.forge.sdk.workflow.models.workflow import WorkflowRunStatus--# Skip the entire module when the cloud-only workers package is not available-pytest.importorskip("workers.temporal_v2_worker.activities")---def _import_activities_module(monkeypatch: pytest.MonkeyPatch):- # activities.py imports cloud-only modules at import time, so these tests- # stub them and re-import the module for each test case.- from dataclasses import dataclass- from typing import Optional-- cloud_package = ModuleType("cloud")- cloud_package.__path__ = []- cloud_services = ModuleType("cloud.services")- data_scrubber_module = ModuleType("cloud.services.data_scrubber_service")- workers_package = ModuleType("workers")- workers_package.__path__ = []- worker_utils_module = ModuleType("workers.worker_utils")- run_parameters_module = ModuleType("workers.run_parameters")-- class DataScrubber:- pass-- async def activity_teardown() -> None:- return None-- @dataclass- class RunSkyvernWorkflowParams:- organization_id: str- workflow_run_id: str- is_scheduled_run: bool = False- workflow_permanent_id: Optional[str] = None- workflow_schedule_id: Optional[str] = None-- data_scrubber_module.DataScrubber = DataScrubber- worker_utils_module.activity_teardown = activity_teardown- run_parameters_module.RunSkyvernWorkflowParams = RunSkyvernWorkflowParams- monkeypatch.setitem(sys.modules, "cloud", cloud_package)- monkeypatch.setitem(sys.modules, "cloud.services", cloud_services)- monkeypatch.setitem(sys.modules, "cloud.services.data_scrubber_service", data_scrubber_module)- temporal_v2_worker_package = ModuleType("workers.temporal_v2_worker")- temporal_v2_worker_package.__path__ = []- monkeypatch.setitem(sys.modules, "workers", workers_package)- monkeypatch.setitem(sys.modules, "workers.worker_utils", worker_utils_module)- monkeypatch.setitem(sys.modules, "workers.run_parameters", run_parameters_module)- monkeypatch.setitem(sys.modules, "workers.temporal_v2_worker", temporal_v2_worker_package)- sys.modules.pop("workers.temporal_v2_worker.activities", None)- activities = importlib.import_module("workers.temporal_v2_worker.activities")- return activities, RunSkyvernWorkflowParams---async def test_setup_scheduled_workflow_run_sets_trigger_metadata(- monkeypatch: pytest.MonkeyPatch,-) -> None:- activities, RunSkyvernWorkflowParams = _import_activities_module(monkeypatch)- created_workflow_run = SimpleNamespace(workflow_run_id="wr_sched_123", status=WorkflowRunStatus.created)- queued_workflow_run = SimpleNamespace(workflow_run_id="wr_sched_123", status=WorkflowRunStatus.queued)- organization = SimpleNamespace(organization_id="org_123")- workflow = SimpleNamespace(title="Scheduled Workflow")-- fake_db = SimpleNamespace(- get_workflow_run=AsyncMock(return_value=None),- get_organization=AsyncMock(return_value=organization),- update_workflow_run=AsyncMock(return_value=queued_workflow_run),- get_run=AsyncMock(return_value=None),- create_task_run=AsyncMock(),- )- fake_workflow_service = SimpleNamespace(- setup_workflow_run=AsyncMock(return_value=created_workflow_run),- get_workflow_by_permanent_id=AsyncMock(return_value=workflow),- )-- monkeypatch.setattr(activities.app, "DATABASE", fake_db)- monkeypatch.setattr(activities.app, "WORKFLOW_SERVICE", fake_workflow_service)-- result = await activities.setup_scheduled_workflow_run(- organization_id="org_123",- workflow_permanent_id="wpid_123",- workflow_schedule_id="ws_123",- temporal_workflow_id="temporal_sched_123",- parameters={"key": "value"},- workflow_run_id="wr_sched_123",- )-- assert result == "wr_sched_123"- assert (- fake_workflow_service.setup_workflow_run.await_args.kwargs["trigger_type"] == WorkflowRunTriggerType.scheduled- )- assert fake_workflow_service.setup_workflow_run.await_args.kwargs["workflow_schedule_id"] == "ws_123"- fake_db.update_workflow_run.assert_awaited_once_with(- workflow_run_id="wr_sched_123",- status=WorkflowRunStatus.queued,- job_id="temporal_sched_123",- )- fake_db.create_task_run.assert_awaited_once()---async def test_setup_scheduled_workflow_run_reuses_existing_run_without_duplicate_task_run(- monkeypatch: pytest.MonkeyPatch,-) -> None:- activities, RunSkyvernWorkflowParams = _import_activities_module(monkeypatch)- existing_workflow_run = SimpleNamespace(workflow_run_id="wr_sched_123", status=WorkflowRunStatus.queued)- organization = SimpleNamespace(organization_id="org_123")-- fake_db = SimpleNamespace(- get_workflow_run=AsyncMock(return_value=existing_workflow_run),- get_organization=AsyncMock(return_value=organization),- update_workflow_run=AsyncMock(),- get_run=AsyncMock(return_value=SimpleNamespace(run_id="wr_sched_123")),- create_task_run=AsyncMock(),- )- fake_workflow_service = SimpleNamespace(- setup_workflow_run=AsyncMock(),- get_workflow_by_permanent_id=AsyncMock(return_value=SimpleNamespace(title="Scheduled Workflow")),- )-- monkeypatch.setattr(activities.app, "DATABASE", fake_db)- monkeypatch.setattr(activities.app, "WORKFLOW_SERVICE", fake_workflow_service)-- result = await activities.setup_scheduled_workflow_run(- organization_id="org_123",- workflow_permanent_id="wpid_123",- workflow_schedule_id="ws_123",- temporal_workflow_id="temporal_sched_123",- parameters={"key": "value"},- workflow_run_id="wr_sched_123",- )-- assert result == "wr_sched_123"- fake_workflow_service.setup_workflow_run.assert_not_awaited()- fake_db.update_workflow_run.assert_not_awaited()- fake_db.create_task_run.assert_not_awaited()---async def test_setup_scheduled_workflow_run_requeues_existing_created_run(- monkeypatch: pytest.MonkeyPatch,-) -> None:- activities, RunSkyvernWorkflowParams = _import_activities_module(monkeypatch)- existing_workflow_run = SimpleNamespace(workflow_run_id="wr_sched_123", status=WorkflowRunStatus.created)- queued_workflow_run = SimpleNamespace(workflow_run_id="wr_sched_123", status=WorkflowRunStatus.queued)- organization = SimpleNamespace(organization_id="org_123")-- fake_db = SimpleNamespace(- get_workflow_run=AsyncMock(return_value=existing_workflow_run),- get_organization=AsyncMock(return_value=organization),- update_workflow_run=AsyncMock(return_value=queued_workflow_run),- get_run=AsyncMock(return_value=None),- create_task_run=AsyncMock(),- )- fake_workflow_service = SimpleNamespace(- setup_workflow_run=AsyncMock(),- get_workflow_by_permanent_id=AsyncMock(return_value=SimpleNamespace(title="Scheduled Workflow")),- )-- monkeypatch.setattr(activities.app, "DATABASE", fake_db)- monkeypatch.setattr(activities.app, "WORKFLOW_SERVICE", fake_workflow_service)-- result = await activities.setup_scheduled_workflow_run(- organization_id="org_123",- workflow_permanent_id="wpid_123",- workflow_schedule_id="ws_123",- temporal_workflow_id="temporal_sched_123",- parameters={"key": "value"},- workflow_run_id="wr_sched_123",- )-- assert result == "wr_sched_123"- fake_workflow_service.setup_workflow_run.assert_not_awaited()- fake_db.update_workflow_run.assert_awaited_once_with(- workflow_run_id="wr_sched_123",- status=WorkflowRunStatus.queued,- job_id="temporal_sched_123",- )- fake_db.create_task_run.assert_awaited_once()---async def test_run_workflow_activity_rejects_scheduled_runs_without_workflow_permanent_id(- monkeypatch: pytest.MonkeyPatch,-) -> None:- activities, RunSkyvernWorkflowParams = _import_activities_module(monkeypatch)- run_workflow_module = ModuleType("scripts.run_workflow")- run_workflow_module.execute_workflow = AsyncMock()- monkeypatch.setitem(sys.modules, "scripts.run_workflow", run_workflow_module)- monkeypatch.setattr(- activities.otel_trace,- "get_current_span",- lambda: SimpleNamespace(set_attribute=lambda *args, **kwargs: None),- )- monkeypatch.setattr(activities.os, "makedirs", lambda *args, **kwargs: None)-- with pytest.raises(RuntimeError, match="workflow_permanent_id"):- await activities.run_workflow_activity(- RunSkyvernWorkflowParams(- organization_id="org_123",- workflow_run_id="",- is_scheduled_run=True,- workflow_schedule_id="ws_123",- )- )---async def test_run_workflow_activity_rejects_scheduled_runs_without_schedule_id(- monkeypatch: pytest.MonkeyPatch,-) -> None:- activities, RunSkyvernWorkflowParams = _import_activities_module(monkeypatch)- run_workflow_module = ModuleType("scripts.run_workflow")- run_workflow_module.execute_workflow = AsyncMock()- monkeypatch.setitem(sys.modules, "scripts.run_workflow", run_workflow_module)- monkeypatch.setattr(- activities.otel_trace,- "get_current_span",- lambda: SimpleNamespace(set_attribute=lambda *args, **kwargs: None),- )- monkeypatch.setattr(activities.os, "makedirs", lambda *args, **kwargs: None)-- with pytest.raises(RuntimeError, match="workflow_schedule_id"):- await activities.run_workflow_activity(- RunSkyvernWorkflowParams(- organization_id="org_123",- workflow_run_id="",- workflow_permanent_id="wpid_123",- is_scheduled_run=True,- )- )