@@ -99,9 +99,6 @@ def test_throw_exception_handler(pact):
9999
100100## Provider
101101
102- Note: The current example only tests the consumer side.
103- In the future, provider tests will also be included.
104-
105102```
106103+-------------------+ +-----------+
107104|(Message Provider) | message | (Pact) |
@@ -110,10 +107,82 @@ In the future, provider tests will also be included.
110107+-------------------+ +-----------+
111108```
112109
113- ## E2E Messaging
110+ ``` python
111+ import pytest
112+ from pact import MessageProvider
113+
114+ def document_created_handler ():
115+ return {
116+ " event" : " ObjectCreated:Put" ,
117+ " documentName" : " document.doc" ,
118+ " creator" : " TP" ,
119+ " documentType" : " microsoft-word"
120+ }
121+
122+
123+ def test_verify_success ():
124+ provider = MessageProvider(
125+ message_providers = {
126+ ' A document created successfully' : document_created_handler
127+ },
128+ provider = ' ContentProvider' ,
129+ consumer = ' DetectContentLambda' ,
130+ pact_dir = ' pacts'
131+
132+ )
133+ with provider:
134+ provider.verify()
135+ ```
136+
137+
138+ ### Provider with pact broker
139+ ``` python
140+ import pytest
141+ from pact import MessageProvider
142+
143+
144+ PACT_BROKER_URL = " http://localhost"
145+ PACT_BROKER_USERNAME = " pactbroker"
146+ PACT_BROKER_PASSWORD = " pactbroker"
147+ PACT_DIR = " pacts"
148+
149+
150+ @pytest.fixture
151+ def default_opts ():
152+ return {
153+ ' broker_username' : PACT_BROKER_USERNAME ,
154+ ' broker_password' : PACT_BROKER_PASSWORD ,
155+ ' broker_url' : PACT_BROKER_URL ,
156+ ' publish_version' : ' 3' ,
157+ ' publish_verification_results' : False
158+ }
159+
160+ def document_created_handler ():
161+ return {
162+ " event" : " ObjectCreated:Put" ,
163+ " documentName" : " document.doc" ,
164+ " creator" : " TP" ,
165+ " documentType" : " microsoft-word"
166+ }
114167
115- Note: The current example only tests the consumer side.
116- In the future, provider tests will also be included.
168+ def test_verify_from_broker (default_opts ):
169+ provider = MessageProvider(
170+ message_providers = {
171+ ' A document created successfully' : document_created_handler,
172+ },
173+ provider = ' ContentProvider' ,
174+ consumer = ' DetectContentLambda' ,
175+ pact_dir = ' pacts'
176+
177+ )
178+
179+ with pytest.raises(AssertionError ):
180+ with provider:
181+ provider.verify_with_broker(** default_opts)
182+
183+ ```
184+
185+ ## E2E Messaging
117186
118187```
119188+-------------------+ +-----------+ +-------------------+
0 commit comments