@@ -26,7 +26,12 @@ Starting from *3.7.0*, Mocket major version will follow the same numbering patte
26
26
27
27
Support it
28
28
==========
29
- *Star * the project on GitHub, Buy Me a Coffee or, even better, contribute with patches or documentation.
29
+ *Star * the project on GitHub, *Buy Me a Coffee * clicking the button below or, even better, contribute with patches or documentation.
30
+
31
+ Thanks to `@felixonmars `_ Mocket is available in the `Arch Linux repository `_.
32
+
33
+ .. _`@felixonmars` : https://github.com/felixonmars
34
+ .. _`Arch Linux repository` : https://www.archlinux.org/packages/community/any/python-mocket/
30
35
31
36
.. image :: https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png
32
37
:target: https://www.buymeacoffee.com/mULbInw5z
@@ -82,53 +87,53 @@ As second step, we create an `example.py` file as the following one:
82
87
.. code-block :: python
83
88
84
89
import json
85
-
90
+
86
91
from mocket import mocketize
87
92
from mocket.mockhttp import Entry
88
93
import requests
89
94
import pytest
90
-
91
-
95
+
96
+
92
97
@pytest.fixture
93
98
def response ():
94
99
return {
95
100
" integer" : 1 ,
96
101
" string" : " asd" ,
97
102
" boolean" : False ,
98
103
}
99
-
100
-
104
+
105
+
101
106
@mocketize # use its decorator
102
107
def test_json (response ):
103
108
url_to_mock = ' https://testme.org/json'
104
-
109
+
105
110
Entry.single_register(
106
111
Entry.GET ,
107
112
url_to_mock,
108
113
body = json.dumps(response),
109
114
headers = {' content-type' : ' application/json' }
110
115
)
111
-
116
+
112
117
mocked_response = requests.get(url_to_mock).json()
113
-
118
+
114
119
assert response == mocked_response
115
120
116
121
# OR use its context manager
117
122
from mocket import Mocketizer
118
-
123
+
119
124
def test_json_with_context_manager (response ):
120
125
url_to_mock = ' https://testme.org/json'
121
-
126
+
122
127
Entry.single_register(
123
128
Entry.GET ,
124
129
url_to_mock,
125
130
body = json.dumps(response),
126
131
headers = {' content-type' : ' application/json' }
127
132
)
128
-
133
+
129
134
with Mocketizer():
130
135
mocked_response = requests.get(url_to_mock).json()
131
-
136
+
132
137
assert response == mocked_response
133
138
134
139
Let's fire our example test::
@@ -183,7 +188,7 @@ What about the other socket animals?
183
188
====================================
184
189
Using *Mocket * with asyncio based clients::
185
190
186
- $ pip install aiohttp
191
+ $ pip install aiohttp
187
192
188
193
Example:
189
194
0 commit comments