METADATA 4.5 KB

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