|
| 1 | +# |
| 2 | +# Test the transcript has all the expected values |
| 3 | +# |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +import feditest |
| 8 | +from feditest import nodedriver, test |
| 9 | +from feditest.utils import FEDITEST_VERSION |
| 10 | +from feditest.testplan import TestPlan, TestPlanConstellation, TestPlanConstellationNode, TestPlanSessionTemplate, TestPlanTestSpec |
| 11 | +from feditest.testrun import TestRun |
| 12 | +from feditest.testruncontroller import AutomaticTestRunController |
| 13 | +from feditest.testruntranscript import TestRunResultTranscript |
| 14 | + |
| 15 | +from dummy import DummyNodeDriver |
| 16 | + |
| 17 | +APP_NAMES = [ |
| 18 | + 'APP_0', |
| 19 | + 'APP_1', |
| 20 | + 'APP_2', |
| 21 | + 'APP_3' |
| 22 | +] |
| 23 | +driver_names = [] |
| 24 | + |
| 25 | +@pytest.fixture(scope="module", autouse=True) |
| 26 | +def init_node_drivers(): |
| 27 | + global driver_names |
| 28 | + |
| 29 | + """ Keep these isolated to this module """ |
| 30 | + feditest.all_node_drivers = {} |
| 31 | + feditest._loading_node_drivers = True |
| 32 | + |
| 33 | + @nodedriver |
| 34 | + class NodeDriver1(DummyNodeDriver): |
| 35 | + pass |
| 36 | + |
| 37 | + @nodedriver |
| 38 | + class NodeDriver2(DummyNodeDriver): |
| 39 | + pass |
| 40 | + |
| 41 | + feditest._loading_node_drivers = False |
| 42 | + |
| 43 | + driver_names = list(feditest.all_node_drivers.keys()) |
| 44 | + |
| 45 | + |
| 46 | +@pytest.fixture(scope="module", autouse=True) |
| 47 | +def init_tests(): |
| 48 | + """ |
| 49 | + Cleanly define some tests. |
| 50 | + """ |
| 51 | + feditest.all_tests = {} |
| 52 | + feditest._registered_as_test = {} |
| 53 | + feditest._registered_as_test_step = {} |
| 54 | + feditest._loading_tests = True |
| 55 | + |
| 56 | + ## |
| 57 | + ## FediTest tests start here |
| 58 | + ## |
| 59 | + |
| 60 | + @test |
| 61 | + def passes() -> None: |
| 62 | + """ |
| 63 | + This test always passes. |
| 64 | + """ |
| 65 | + return |
| 66 | + |
| 67 | + ## |
| 68 | + ## FediTest tests end here |
| 69 | + ## (Don't forget the next two lines) |
| 70 | + ## |
| 71 | + |
| 72 | + feditest._loading_tests = False |
| 73 | + feditest._load_tests_pass2() |
| 74 | + |
| 75 | + |
| 76 | +@pytest.fixture(autouse=True) |
| 77 | +def test_plan_fixture() -> TestPlan: |
| 78 | + """ |
| 79 | + The test plan tests all known tests. |
| 80 | + """ |
| 81 | + constellations = [ |
| 82 | + TestPlanConstellation( |
| 83 | + { |
| 84 | + 'node1a': TestPlanConstellationNode( |
| 85 | + driver_names[0], |
| 86 | + { |
| 87 | + 'app' : APP_NAMES[0] |
| 88 | + } |
| 89 | + ), |
| 90 | + 'node2a': TestPlanConstellationNode( |
| 91 | + driver_names[1], |
| 92 | + { |
| 93 | + 'app' : APP_NAMES[1] |
| 94 | + } |
| 95 | + ) |
| 96 | + }, |
| 97 | + 'constellation-1'), |
| 98 | + TestPlanConstellation( |
| 99 | + { |
| 100 | + 'node1b': TestPlanConstellationNode( |
| 101 | + driver_names[0], |
| 102 | + { |
| 103 | + 'app' : APP_NAMES[2] |
| 104 | + } |
| 105 | + ), |
| 106 | + 'node2b': TestPlanConstellationNode( |
| 107 | + driver_names[1], |
| 108 | + { |
| 109 | + 'app' : APP_NAMES[3] |
| 110 | + } |
| 111 | + ) |
| 112 | + }, |
| 113 | + 'constellation-2') |
| 114 | + ] |
| 115 | + tests = [ TestPlanTestSpec(name) for name in sorted(feditest.all_tests.keys()) if feditest.all_tests.get(name) is not None ] |
| 116 | + session = TestPlanSessionTemplate(tests, "Test a test that passes") |
| 117 | + ret = TestPlan(session, constellations) |
| 118 | + ret.properties_validate() |
| 119 | + # ret.print() |
| 120 | + return ret |
| 121 | + |
| 122 | + |
| 123 | +@pytest.fixture |
| 124 | +def transcript(test_plan_fixture: TestPlan) -> TestRunResultTranscript: |
| 125 | + test_plan_fixture.check_can_be_executed() |
| 126 | + |
| 127 | + test_run = TestRun(test_plan_fixture) |
| 128 | + controller = AutomaticTestRunController(test_run) |
| 129 | + test_run.run(controller) |
| 130 | + |
| 131 | + ret = test_run.transcribe() |
| 132 | + return ret |
| 133 | + |
| 134 | + |
| 135 | +def test_transcript(transcript: TestRunResultTranscript): |
| 136 | + assert transcript.plan |
| 137 | + assert transcript.id |
| 138 | + assert transcript.started |
| 139 | + assert transcript.ended |
| 140 | + |
| 141 | + assert len(transcript.sessions) == 2 |
| 142 | + assert len(transcript.test_meta) == 1 |
| 143 | + assert transcript.result is None |
| 144 | + assert transcript.type == 'feditest-testrun-transcript' |
| 145 | + assert transcript.feditest_version == FEDITEST_VERSION |
| 146 | + |
| 147 | + for i in range(0, 1): |
| 148 | + assert transcript.sessions[i].started |
| 149 | + assert transcript.sessions[i].ended |
| 150 | + assert len(transcript.sessions[i].run_tests) == 1 |
| 151 | + assert transcript.sessions[i].run_tests[0].started |
| 152 | + assert transcript.sessions[i].run_tests[0].ended |
| 153 | + assert transcript.sessions[i].run_tests[0].result is None |
| 154 | + |
0 commit comments