METADATA 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. Metadata-Version: 2.1
  2. Name: requests-mock
  3. Version: 1.12.1
  4. Summary: Mock out responses from the requests package
  5. Home-page: https://requests-mock.readthedocs.io/
  6. Author: Jamie Lennox
  7. Author-email: jamielennox@gmail.com
  8. License: Apache-2
  9. Project-URL: Source, https://github.com/jamielennox/requests-mock
  10. Classifier: Development Status :: 5 - Production/Stable
  11. Classifier: Intended Audience :: Developers
  12. Classifier: Intended Audience :: Information Technology
  13. Classifier: License :: OSI Approved :: Apache Software License
  14. Classifier: Operating System :: OS Independent
  15. Classifier: Programming Language :: Python
  16. Classifier: Programming Language :: Python :: 3
  17. Classifier: Programming Language :: Python :: 3.8
  18. Classifier: Programming Language :: Python :: 3.9
  19. Classifier: Programming Language :: Python :: 3.10
  20. Classifier: Programming Language :: Python :: 3.11
  21. Classifier: Programming Language :: Python :: 3.12
  22. Classifier: Programming Language :: Python :: Implementation :: CPython
  23. Classifier: Programming Language :: Python :: Implementation :: PyPy
  24. Classifier: Topic :: Software Development :: Testing
  25. Requires-Python: >=3.5
  26. License-File: LICENSE
  27. Requires-Dist: requests <3,>=2.22
  28. Provides-Extra: fixture
  29. Requires-Dist: fixtures ; extra == 'fixture'
  30. ===============================
  31. requests-mock
  32. ===============================
  33. .. image:: https://badge.fury.io/py/requests-mock.png
  34. :target: https://pypi.org/project/requests-mock/
  35. Intro
  36. =====
  37. `requests-mock` provides a building block to stub out the HTTP `requests`_ portions of your testing code.
  38. You should checkout the `docs`_ for more information.
  39. The Basics
  40. ==========
  41. Everything in `requests`_ eventually goes through an adapter to do the transport work.
  42. `requests-mock` creates a custom `adapter` that allows you to predefine responses when certain URIs are called.
  43. There are then a number of methods provided to get the adapter used.
  44. A simple example:
  45. .. code:: python
  46. >>> import requests
  47. >>> import requests_mock
  48. >>> session = requests.Session()
  49. >>> adapter = requests_mock.Adapter()
  50. >>> session.mount('mock://', adapter)
  51. >>> adapter.register_uri('GET', 'mock://test.com', text='data')
  52. >>> resp = session.get('mock://test.com')
  53. >>> resp.status_code, resp.text
  54. (200, 'data')
  55. Obviously having all URLs be `mock://` prefixed isn't going to be useful,
  56. so you can use `requests_mock.Mocker` to get the adapter into place.
  57. As a context manager:
  58. .. code:: python
  59. >>> with requests_mock.Mocker() as m:
  60. ... m.get('http://test.com', text='data')
  61. ... requests.get('http://test.com').text
  62. ...
  63. 'data'
  64. Or as a decorator:
  65. .. code:: python
  66. >>> @requests_mock.Mocker()
  67. ... def test_func(m):
  68. ... m.get('http://test.com', text='data')
  69. ... return requests.get('http://test.com').text
  70. ...
  71. >>> test_func()
  72. 'data'
  73. Or as a pytest fixture:
  74. .. code:: python
  75. >>> def test_simple(requests_mock):
  76. ... requests_mock.get('http://test.com', text='data')
  77. ... assert 'data' == requests.get('http://test.com').text
  78. For more information checkout the `docs`_.
  79. Reporting Bugs
  80. ==============
  81. Development and bug tracking is performed on `GitHub`_.
  82. Questions
  83. =========
  84. There is a tag dedicated to `requests-mock` on `StackOverflow`_ where you can ask usage questions.
  85. License
  86. =======
  87. Licensed under the Apache License, Version 2.0 (the "License"); you may
  88. not use this file except in compliance with the License. You may obtain
  89. a copy of the License at
  90. https://www.apache.org/licenses/LICENSE-2.0
  91. Unless required by applicable law or agreed to in writing, software
  92. distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  93. WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  94. License for the specific language governing permissions and limitations
  95. under the License.
  96. .. _requests: https://requests.readthedocs.io
  97. .. _docs: https://requests-mock.readthedocs.io/
  98. .. _GitHub: https://github.com/jamielennox/requests-mock
  99. .. _StackOverflow: https://stackoverflow.com/questions/tagged/requests-mock