|
1 | 1 | from cdevents.core import event_type |
2 | 2 | import pytest |
3 | 3 |
|
4 | | -from cdevents.core.events import Events |
| 4 | +from cdevents.core.service import Service, ServiceType |
5 | 5 |
|
6 | 6 | @pytest.mark.unit |
7 | 7 | def test_service_deployed(): |
8 | | - event = Events().create_service_event(event_type.ServiceDeployedEventV1, envid="_envid", name="_name", version="_version", data={"service": "_service"}) |
9 | | - assert event is not None |
10 | | - assert event._attributes["type"] == event_type.ServiceDeployedEventV1 |
11 | | - assert event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
12 | | - assert event.data == {"service": "_service"} |
| 8 | + service = Service(service_type=ServiceType.ServiceDeployedEventV1, envid="_envid", name="_name", version="_version") |
| 9 | + service_event = service.create_event(data={"key1": "value1"}) |
| 10 | + assert service_event is not None |
| 11 | + assert service_event._attributes["type"] == ServiceType.ServiceDeployedEventV1.value |
| 12 | + assert service_event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
| 13 | + assert service_event.data == {"key1": "value1"} |
13 | 14 |
|
14 | 15 |
|
15 | 16 | @pytest.mark.unit |
16 | 17 | def test_service_upgraded(): |
17 | | - event = Events().create_service_event(event_type.ServiceUpgradedEventV1, envid="_envid", name="_name", version="_version", data={"service": "_service"}) |
18 | | - assert event is not None |
19 | | - assert event._attributes["type"] == event_type.ServiceUpgradedEventV1 |
20 | | - assert event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
21 | | - assert event.data == {"service": "_service"} |
| 18 | + service = Service(service_type=ServiceType.ServiceUpgradedEventV1, envid="_envid", name="_name", version="_version") |
| 19 | + service_event = service.create_event(data={"key1": "value1"}) |
| 20 | + assert service_event is not None |
| 21 | + assert service_event._attributes["type"] == ServiceType.ServiceUpgradedEventV1.value |
| 22 | + assert service_event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
| 23 | + assert service_event.data == {"key1": "value1"} |
22 | 24 |
|
23 | 25 |
|
24 | 26 | @pytest.mark.unit |
25 | 27 | def test_service_rolledback(): |
26 | | - event = Events().create_service_event(event_type.ServiceRolledbackEventV1, envid="_envid", name="_name", version="_version", data={"service": "_service"}) |
27 | | - assert event is not None |
28 | | - assert event._attributes["type"] == event_type.ServiceRolledbackEventV1 |
29 | | - assert event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
30 | | - assert event.data == {"service": "_service"} |
| 28 | + service = Service(service_type=ServiceType.ServiceRolledbackEventV1, envid="_envid", name="_name", version="_version") |
| 29 | + service_event = service.create_event(data={"key1": "value1"}) |
| 30 | + assert service_event is not None |
| 31 | + assert service_event._attributes["type"] == ServiceType.ServiceRolledbackEventV1.value |
| 32 | + assert service_event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
| 33 | + assert service_event.data == {"key1": "value1"} |
31 | 34 |
|
32 | 35 |
|
33 | 36 | @pytest.mark.unit |
34 | 37 | def test_service_removed(): |
35 | | - event = Events().create_service_event(event_type.ServiceRemovedEventV1, envid="_envid", name="_name", version="_version", data={"service": "_service"}) |
36 | | - assert event is not None |
37 | | - assert event._attributes["type"] == event_type.ServiceRemovedEventV1 |
38 | | - assert event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
39 | | - assert event.data == {"service": "_service"} |
| 38 | + service = Service(service_type=ServiceType.ServiceRemovedEventV1, envid="_envid", name="_name", version="_version") |
| 39 | + service_event = service.create_event(data={"key1": "value1"}) |
| 40 | + assert service_event is not None |
| 41 | + assert service_event._attributes["type"] == ServiceType.ServiceRemovedEventV1.value |
| 42 | + assert service_event._attributes["extensions"] == {"serviceenvid": "_envid", "servicename": "_name", "serviceversion": "_version"} |
| 43 | + assert service_event.data == {"key1": "value1"} |
40 | 44 |
|
0 commit comments