File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ client.stub(
6666
6767(For when calling another component * IS* what you are testing)
6868
69- Using the ` expect ` will remember the request and verify it when ` verify ` is called.
69+ Using the ` expect ` will remember the request and verify it when ` verify_expectations ` is called.
7070
7171```
7272import json
@@ -80,7 +80,7 @@ client.expect(
8080 times(1)
8181)
8282
83- client.verify () # AssertionError !
83+ client.verify_expectations () # AssertionError !
8484```
8585
8686* The ` times(N) ` parameter is mandatory for expect
@@ -161,6 +161,18 @@ client.expect(
161161```
162162I.e. this will match ` {"key": "value"} ` or ` {"key": "value", "another": "key"} `
163163
164+ ### Verifying request
165+
166+ ```
167+ from mockserver import MockServerClient, request, times
168+
169+ client = MockServerClient("http://localhost:1080")
170+ client.verify(
171+ request(path="/some_path", querystring({"key": "value"})),
172+ times(1)
173+ )
174+ ```
175+ Verify will check request on MockServer and raise AssertionError if request not found.
164176
165177## More documentation
166178
@@ -182,7 +194,7 @@ class ServerMockingTestBase(...):
182194 def tearDown(self):
183195 super(ServerMockingTestBase, self).tearDown()
184196
185- self.client.verify ()
197+ self.client.verify_expectations ()
186198```
187199
188200# Troubleshooting
Original file line number Diff line number Diff line change 44
55
66class TestBasicExpectations (MockServerClientTestCase ):
7+ def test_expect_once_not_called_fails (self ):
8+ self .client .expect (
9+ request (),
10+ response (),
11+ times (1 )
12+ )
13+
14+ with self .assertRaises (AssertionError ):
15+ self .client .verify_expectations ()
16+
717 def test_expect_once_called_twice_fails (self ):
818 self .client .expect (
919 request (),
@@ -17,6 +27,15 @@ def test_expect_once_called_twice_fails(self):
1727 result = requests .get (MOCK_SERVER_URL + "/path" )
1828 self .assertEqual (result .status_code , 404 )
1929
30+ def test_expect_never (self ):
31+ self .client .expect (
32+ request (),
33+ response (),
34+ times (0 )
35+ )
36+
37+ self .client .verify_expectations ()
38+
2039 def test_reset_should_clear_expectations (self ):
2140 self .client .expect (
2241 request (),
Original file line number Diff line number Diff line change 44
55
66class TestBasicVerifying (MockServerClientTestCase ):
7- def test_verify_request_recived_once (self ):
7+ def test_verify_request_received_once (self ):
88 requests .get (MOCK_SERVER_URL )
99 self .client .verify (request (), times (1 ))
1010
11- def test_verify_request_never_recived (self ):
11+ def test_verify_request_never_received (self ):
1212 self .client .verify (request (), times (0 ))
1313
14- def test_verify_request_not_recived_fail (self ):
14+ def test_verify_request_not_received_fail (self ):
1515 with self .assertRaises (AssertionError ):
1616 self .client .verify (request (), times (1 ))
1717
You can’t perform that action at this time.
0 commit comments