This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_validation.py
117 lines (94 loc) · 4.03 KB
/
test_validation.py
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import pytest
import streamdal.validation as validation
import streamdal_protos.protos as protos
class TestTailRequest:
cmd: protos.Command
@pytest.fixture(autouse=True)
def before_each(self):
self.cmd = protos.Command()
self.cmd.tail = protos.TailCommand()
self.cmd.tail.request = protos.TailRequest()
self.cmd.tail.request.audience = protos.Audience()
self.cmd.tail.request.id = "test_id"
self.cmd.tail.request.type = protos.TailRequestType.TAIL_REQUEST_TYPE_START
def test_valid_tail_request(self):
# Should not raise any exception
validation.tail_request(self.cmd)
def test_invalid_command_type(self):
with pytest.raises(ValueError, match="cmd must be a protos.Command"):
validation.tail_request(None)
def test_invalid_tail_command_type(self):
self.cmd.tail = protos.Command()
with pytest.raises(ValueError, match="cmd.tail must be a protos.TailCommand"):
validation.tail_request(self.cmd)
def test_invalid_tail_request_type(self):
self.cmd.tail.request = protos.Command()
with pytest.raises(
ValueError, match="cmd.tail.request must be a protos.TailRequest"
):
validation.tail_request(self.cmd)
def test_invalid_audience_type(self):
self.cmd.tail.request.audience = protos.Command()
with pytest.raises(
ValueError, match="cmd.tail.request.audience must be a protos.Audience"
):
validation.tail_request(self.cmd)
def test_empty_request_id(self):
self.cmd.tail.request.id = ""
with pytest.raises(ValueError, match="cmd.tail.request.id must be non-empty"):
validation.tail_request(self.cmd)
def test_unset_request_type(self):
self.cmd.tail.request.type = protos.TailRequestType.TAIL_REQUEST_TYPE_UNSET
with pytest.raises(ValueError, match="cmd.tail.request.type cannot be unset"):
validation.tail_request(self.cmd)
class TestSetPipelines:
def test_valid_input(self):
# Create a valid protos.Command object
cmd = protos.Command(
audience=protos.Audience(),
set_pipelines=protos.SetPipelinesCommand(
pipelines=[protos.Pipeline(id="some_id")]
),
)
# The function should not raise any exceptions for valid input
validation.set_pipelines(cmd)
def test_invalid_command_type(self):
with pytest.raises(ValueError, match="cmd must be a protos.Command"):
validation.set_pipelines(
None
) # Passing a mock object instead of a protos.Command
def test_invalid_audience_type(self):
invalid_cmd = protos.Command(
audience=None,
set_pipelines=protos.SetPipelinesCommand(
pipelines=[protos.Pipeline(id="some_id")]
),
)
with pytest.raises(ValueError, match="cmd.audience must be a protos.Audience"):
validation.set_pipelines(invalid_cmd)
def test_invalid_attach_pipeline_type(self):
invalid_cmd = protos.Command(
audience=protos.Audience(),
set_pipelines=None,
)
with pytest.raises(
ValueError,
match="cmd.set_pipelines must be a protos.SetPipelinesCommand",
):
validation.set_pipelines(invalid_cmd)
def test_invalid_pipeline_type(self):
invalid_cmd = protos.Command(
audience=protos.Audience(),
set_pipelines=protos.SetPipelinesCommand(pipelines=[protos.Pipeline()]),
)
with pytest.raises(ValueError):
validation.set_pipelines(invalid_cmd)
def test_empty_pipeline_id(self):
invalid_cmd = protos.Command(
audience=protos.Audience(),
set_pipelines=protos.SetPipelinesCommand(
pipelines=[protos.Pipeline(id="")]
),
)
with pytest.raises(ValueError, match="pipeline.id must be non-empty"):
validation.set_pipelines(invalid_cmd)