"""Functional tests for rds.py query functions against an in-memory SQLite DB.""" import pytest from trigger.constants import SplitType from trigger.schemas import SplitRow from trigger.utils import rds class TestGetReportRun: def test_returns_period_ids_and_trigger_type(self): period_ids, trigger_type = rds.get_report_run("run-auto-1") assert period_ids == ["101", "102"] assert trigger_type == "AUTO" def test_manual_run(self): period_ids, trigger_type = rds.get_report_run("run-manual-1") assert period_ids == ["201"] assert trigger_type == "MANUAL" def test_raises_for_unknown_uuid(self): from trigger.utils import LambdaException with pytest.raises(LambdaException): rds.get_report_run("no-such-uuid") class TestGetTrackSplits: def test_returns_track_splits(self): rows = rds.get_track_splits_for_report_run("run-auto-1", []) identifiers = {r.identifier for r in rows} assert "tuid-A" in identifiers assert "tuid-B" in identifiers def test_excludes_subaccount_splits(self): rows = rds.get_track_splits_for_report_run("run-auto-1", []) assert all(r.identifier != "sub-1" for r in rows) def test_returns_typed_rows(self): rows = rds.get_track_splits_for_report_run("run-auto-1", []) assert all(isinstance(r, SplitRow) for r in rows) def test_excludes_invalid_collaborators(self): rows = rds.get_track_splits_for_report_run("run-auto-1", [12]) assert all(r.collaborator_id != 12 for r in rows) def test_split_type_id_is_track(self): rows = rds.get_track_splits_for_report_run("run-auto-1", []) assert all(r.split_type_id == SplitType.TRACK for r in rows) def test_returns_empty_for_unknown_run(self): assert rds.get_track_splits_for_report_run("no-such-run", []) == [] class TestGetSubaccountSplits: def test_returns_subaccount_splits(self): rows = rds.get_subaccount_splits_for_report_run("run-auto-1", []) assert len(rows) == 1 assert rows[0].identifier == "sub-1" assert rows[0].collaborator_id == 10 def test_returns_typed_rows(self): rows = rds.get_subaccount_splits_for_report_run("run-auto-1", []) assert all(isinstance(r, SplitRow) for r in rows) def test_excludes_invalid_collaborators(self): rows = rds.get_subaccount_splits_for_report_run("run-auto-1", [10]) assert rows == [] def test_split_type_id_is_subaccount(self): rows = rds.get_subaccount_splits_for_report_run("run-auto-1", []) assert all(r.split_type_id == SplitType.SUBACCOUNT for r in rows) def test_returns_empty_for_unknown_run(self): assert rds.get_subaccount_splits_for_report_run("no-such-run", []) == [] class TestGetCollaborators: def test_returns_all_collaborators_for_run(self): rows = rds.get_collaborators_for_report_run("run-auto-1", []) ids = {row[0] for row in rows} assert ids == {10, 11, 12} def test_performance_rights_flag(self): rows = rds.get_collaborators_for_report_run("run-auto-1", []) by_id = {row[0]: row[1] for row in rows} assert by_id[10] == 0 assert by_id[11] == 1 def test_excludes_invalid_collaborators(self): rows = rds.get_collaborators_for_report_run("run-auto-1", [12]) ids = {row[0] for row in rows} assert 12 not in ids assert {10, 11} == ids def test_returns_empty_for_unknown_run(self): assert rds.get_collaborators_for_report_run("no-such-run", []) == [] class TestValidateSplits: def test_gross_split_returns_collaborator(self): result = rds.get_collaborators_with_any_gross_split("run-auto-1") assert 10 in result def test_gross_split_no_false_positives(self): result = rds.get_collaborators_with_any_gross_split("run-auto-1") assert 11 not in result def test_gross_split_empty_for_unknown_run(self): assert rds.get_collaborators_with_any_gross_split("no-such-run") == [] def test_split_exceeding_100pc_returns_collaborator(self): result = rds.get_collaborators_with_any_split_exceeding_100pc("run-auto-1") assert 11 in result def test_split_exceeding_100pc_no_false_positives(self): result = rds.get_collaborators_with_any_split_exceeding_100pc("run-auto-1") assert 10 not in result def test_split_exceeding_100pc_empty_for_unknown_run(self): assert rds.get_collaborators_with_any_split_exceeding_100pc("no-such-run") == [] def test_combined_splits_exceeding_100pc_returns_result(self): # tuid-F has collab 10 (0.6) + collab 11 (0.6) = 1.2 combined result = rds.get_collaborators_with_combined_track_splits_exceeding_100pc("run-auto-1") assert len(result) >= 1 assert all(c in {10, 11} for c in result) def test_combined_splits_exceeding_100pc_empty_for_unknown_run(self): result = rds.get_collaborators_with_combined_track_splits_exceeding_100pc("no-such-run") assert result == []