Skip to content

Commit c2d8bf8

Browse files
Evgeniy Semenovlindycoder
authored andcommitted
Update docs with new verify method
(cherry picked from commit b995333)
1 parent 587f17c commit c2d8bf8

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff 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
```
7272
import 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
```
162162
I.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

test/test_basic_expectations.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55

66
class 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(),

test/test_basic_verifying.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55

66
class 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

0 commit comments

Comments
 (0)