8
8
from os .path import isfile
9
9
10
10
from pact import MessageConsumer , Provider
11
+ from pact import matchers
12
+ from pact .matchers import Like , Term
11
13
from src .message_handler import MessageHandler , CustomError
12
14
13
15
log = logging .getLogger (__name__ )
@@ -93,7 +95,7 @@ def test_throw_exception_handler(pact_no_publish):
93
95
with pytest .raises (CustomError ):
94
96
with pact_no_publish :
95
97
# handler needs "documentType" == "microsoft-word"
96
- MessageHandler (wrong_event )
98
+ MessageHandler (matchers . get_generated_values ( wrong_event ) )
97
99
98
100
progressive_delay (f"{ PACT_FILE } " )
99
101
assert isfile (f"{ PACT_FILE } " ) == 0
@@ -104,9 +106,9 @@ def test_put_file(pact_no_publish):
104
106
105
107
expected_event = {
106
108
"event" : "ObjectCreated:Put" ,
107
- "documentName" : "document. doc" ,
108
- "creator" : "TP" ,
109
- "documentType" : "microsoft-word"
109
+ "documentName" : Term ( "^.* \\ .( doc|docx)$" , 'document.doc' ) ,
110
+ "creator" : Like ( "TP" ) ,
111
+ "documentType" : "microsoft-word" ,
110
112
}
111
113
112
114
(pact_no_publish
@@ -118,7 +120,7 @@ def test_put_file(pact_no_publish):
118
120
}))
119
121
120
122
with pact_no_publish :
121
- MessageHandler (expected_event )
123
+ MessageHandler (matchers . get_generated_values ( expected_event ) )
122
124
123
125
progressive_delay (f"{ PACT_FILE } " )
124
126
assert isfile (f"{ PACT_FILE } " ) == 1
@@ -136,9 +138,9 @@ def test_publish_to_broker(pact):
136
138
137
139
expected_event = {
138
140
"event" : "ObjectCreated:Delete" ,
139
- "documentName" : "document. doc" ,
140
- "creator" : "TP" ,
141
- "documentType" : "microsoft-word"
141
+ "documentName" : Term ( "^.* \\ .( doc|docx)$" , 'document.doc' ) ,
142
+ "creator" : Like ( "TP" ) ,
143
+ "documentType" : "microsoft-word" ,
142
144
}
143
145
144
146
(pact
@@ -150,7 +152,10 @@ def test_publish_to_broker(pact):
150
152
}))
151
153
152
154
with pact :
153
- MessageHandler (expected_event )
155
+ # call matchers.get_generated_values(expected_event) to
156
+ # reify/strip the expected_event of the matchers used
157
+ # for Pact
158
+ MessageHandler (matchers .get_generated_values (expected_event ))
154
159
155
160
progressive_delay (f"{ PACT_FILE } " )
156
161
assert isfile (f"{ PACT_FILE } " ) == 1
0 commit comments