File size: 2,106 Bytes
2379054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""End-to-end integration tests."""

from pathlib import Path

import pandas as pd
import pytest

from core.database import clear_project_data, get_connection, insert_chainages
from core.orchestrator import Orchestrator
from core.submission_checker import check_submission_readiness

SAMPLE_XML = Path(__file__).parent / "test_data" / "sample.xml"


def test_orchestrator_full_pipeline():
    assert SAMPLE_XML.exists()
    xml_data = SAMPLE_XML.read_bytes()
    orchestrator = Orchestrator()
    result = orchestrator.run_full_pipeline(
        ex_xml=xml_data,
        pr_xml=xml_data,
        project_name="IntegrationTest",
    )
    assert result["status"] in ["complete", "partial"]
    assert "results" in result
    assert result["results"]["parse_xml"]["status"] == "success"
    assert result["results"]["calculate"]["status"] == "success"
    assert result["results"]["run_qa"]["status"] == "success"
    assert result["results"]["generate_report"]["status"] == "success"
    assert Path(result["report_path"]).exists()


def test_submission_checker():
    df = pd.DataFrame(
        {
            "datum_chainage": [1000, 1010, 1020],
            "level_m": [10.0, 10.5, 11.0],
            "offset_alignment": ["TestTrack"] * 3,
        }
    )
    insert_chainages(df, "existing", source_file="test.xml")
    result = check_submission_readiness(
        project_name="TestProject",
        ex_df=df,
        pr_df=df,
        calculations={1: {"lift": {1000: 5.0}}},
        drawing_issues=[],
        vba_script="x" * 120,
    )
    assert "status" in result
    assert "issues" in result
    assert "recommendation" in result


def test_clear_project_data():
    clear_project_data()


def test_db_schema():
    conn = get_connection()
    cursor = conn.cursor()
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    tables = [row[0] for row in cursor.fetchall()]
    expected = ["chainages", "survey_features", "drawings", "psr", "project_metadata", "provenance"]
    for table in expected:
        assert table in tables, f"Missing table: {table}"
    conn.close()