|
1 | | -from pickle import NONE |
2 | | -from cdevents.core import event_type |
3 | 1 | import pytest |
4 | 2 |
|
5 | | -from cdevents.core.events import Events |
| 3 | +from cdevents.core.pipelinerun import Pipelinerun, PipelinerunType |
6 | 4 |
|
7 | 5 | @pytest.mark.unit |
8 | 6 | def test_pipelinerun_started(): |
9 | | - event = Events().create_pipelinerun_event(event_type.PipelineRunStartedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors", data={"pipelinerun": "_pipelinerun"}) |
10 | | - assert event is not None |
11 | | - assert event._attributes["type"] == event_type.PipelineRunStartedEventV1 |
12 | | - assert event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
13 | | - assert event.data == {"pipelinerun": "_pipelinerun"} |
| 7 | + pipelinerun = Pipelinerun(pipelinerun_type=PipelinerunType.PipelineRunStartedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors") |
| 8 | + pipelinerun_event = pipelinerun.create_event(data={"key1": "value1"}) |
| 9 | + assert pipelinerun_event is not None |
| 10 | + assert pipelinerun_event._attributes["type"] == PipelinerunType.PipelineRunStartedEventV1.value |
| 11 | + assert pipelinerun_event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
| 12 | + assert pipelinerun_event.data == {"key1": "value1"} |
14 | 13 |
|
15 | 14 | @pytest.mark.unit |
16 | 15 | def test_pipelinerun_finished(): |
17 | | - event = Events().create_pipelinerun_event(event_type.PipelineRunFinishedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors", data={"pipelinerun": "_pipelinerun"}) |
18 | | - assert event is not None |
19 | | - assert event._attributes["type"] == event_type.PipelineRunFinishedEventV1 |
20 | | - assert event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
21 | | - assert event.data == {"pipelinerun": "_pipelinerun"} |
| 16 | + pipelinerun = Pipelinerun(pipelinerun_type=PipelinerunType.PipelineRunFinishedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors") |
| 17 | + pipelinerun_event = pipelinerun.create_event(data={"key1": "value1"}) |
| 18 | + assert pipelinerun_event is not None |
| 19 | + assert pipelinerun_event._attributes["type"] == PipelinerunType.PipelineRunFinishedEventV1.value |
| 20 | + assert pipelinerun_event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
| 21 | + assert pipelinerun_event.data == {"key1": "value1"} |
22 | 22 |
|
23 | 23 | @pytest.mark.unit |
24 | 24 | def test_pipelinerun_queued(): |
25 | | - event = Events().create_pipelinerun_event(event_type.PipelineRunQueuedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors", data={"pipelinerun": "_pipelinerun"}) |
26 | | - assert event is not None |
27 | | - assert event._attributes["type"] == event_type.PipelineRunQueuedEventV1 |
28 | | - assert event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
29 | | - assert event.data == {"pipelinerun": "_pipelinerun"} |
| 25 | + pipelinerun = Pipelinerun(pipelinerun_type=PipelinerunType.PipelineRunQueuedEventV1, id="_id", name="_name", status="_status", url="_url", errors="_errors") |
| 26 | + pipelinerun_event = pipelinerun.create_event(data={"key1": "value1"}) |
| 27 | + assert pipelinerun_event is not None |
| 28 | + assert pipelinerun_event._attributes["type"] == PipelinerunType.PipelineRunQueuedEventV1.value |
| 29 | + assert pipelinerun_event._attributes["extensions"] == {"pipelinerunid": "_id", "pipelinerunname": "_name", "pipelinerunstatus": "_status", "pipelinerunurl": "_url", "pipelinerunerrors": "_errors"} |
| 30 | + assert pipelinerun_event.data == {"key1": "value1"} |
0 commit comments