20
20
import main
21
21
22
22
23
- required_fields = ['Ce-Id' , 'Ce-Source' , 'Ce-Type' , 'Ce-Specversion' ]
24
-
25
- header_data = {field : str (uuid4 ()) for field in required_fields }
23
+ binary_headers = {
24
+ "ce-id" : str (uuid4 ),
25
+ "ce-type" : "com.pytest.sample.event" ,
26
+ "ce-source" : "<my-test-source>" ,
27
+ "ce-specversion" : "1.0"
28
+ }
26
29
27
30
28
31
@pytest .fixture
@@ -32,7 +35,7 @@ def client():
32
35
33
36
34
37
def test_endpoint (client , capsys ):
35
- test_headers = copy .copy (header_data )
38
+ test_headers = copy .copy (binary_headers )
36
39
test_headers ['Ce-Subject' ] = 'test-subject'
37
40
38
41
r = client .post ('/' , headers = test_headers )
@@ -43,20 +46,20 @@ def test_endpoint(client, capsys):
43
46
44
47
45
48
def test_missing_subject (client , capsys ):
46
- r = client .post ('/' , headers = header_data )
49
+ r = client .post ('/' , headers = binary_headers )
47
50
assert r .status_code == 400
48
51
49
52
out , _ = capsys .readouterr ()
50
- assert 'Bad Request: expected header Ce-Subject ' in out
53
+ assert 'Bad Request: expected header ce-subject ' in out
51
54
52
55
53
56
def test_missing_required_fields (client , capsys ):
54
- for field in required_fields :
55
- test_headers = copy .copy (header_data )
57
+ for field in binary_headers :
58
+ test_headers = copy .copy (binary_headers )
56
59
test_headers .pop (field )
57
60
58
61
r = client .post ('/' , headers = test_headers )
59
62
assert r .status_code == 400
60
63
61
64
out , _ = capsys .readouterr ()
62
- assert f'Bad Request: missing required header { field } ' in out
65
+ assert 'MissingRequiredFields ' in out
0 commit comments