File: examples.rst

package info (click to toggle)
python-pook 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 672 kB
  • sloc: python: 3,558; makefile: 13
file content (156 lines) | stat: -rw-r--r-- 3,110 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
Examples
========


Basic mocking example using requests
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/requests_client.py



Chainable API DSL
^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/chainable_api.py



Context manager for isolated mocking
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/context_manager.py


Single mock context manager definition for isolated mocking
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/mock_context_manager.py


Declaring mocks as decorators
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/decorators.py


Activating the mock engine via decorator within the function context
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/decorator_activate.py


Activating the mock engine via decorator within an async coroutine function context
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/decorator_activate_async.py


Featured JSON body matching
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/json_matching.py



JSONSchema based body matching
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/json_schema.py


Request Query Params matching
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. literalinclude:: ../examples/query_params_matching.py


Enable real networking mode
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/network_mode.py



Persistent mock
^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/persistent_mock.py



Time TTL limited mock
^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/time_ttl_mock.py



Regular expression matching
^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/regex.py



``unittest`` integration
^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/unittest_example.py



``py.test`` integration
^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/pytest_example.py



Simulated error exception on mock matching
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/simulated_error.py



Using ``urllib3`` as HTTP client
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/urllib3_client.py



Using ``urllib3`` to return a chunked response
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/urllib3_chunked_response.py



Asynchronous HTTP request using ``aiohttp``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/aiohttp_client.py



Using ``http.client`` standard Python package as HTTP client
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/http_client_native.py


Example using `mocket`_ Python library as underlying mock engine
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/mocket_example.py


Hy programming language example
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../examples/basic.hy


.. _mocket: https://github.com/mindflayer/python-mocket