Skip to content

Commit

Permalink
Add a wrapper to PUT (#359)
Browse files Browse the repository at this point in the history
Co-authored-by: Thierry GUIBERT <thierry.guibert@croix-rouge.fr>
  • Loading branch information
titixbrest and titixbrest committed Mar 14, 2021
1 parent f09a46e commit a27ff22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions mechanicalsoup/browser.py
Expand Up @@ -160,6 +160,18 @@ def post(self, *args, **kwargs):
Browser.add_soup(response, self.soup_config)
return response

def put(self, *args, **kwargs):
"""Straightforward wrapper around `requests.Session.put
<http://docs.python-requests.org/en/master/api/#requests.Session.put>`__.
:return: `requests.Response
<http://docs.python-requests.org/en/master/api/#requests.Response>`__
object with a *soup*-attribute added by :func:`add_soup`.
"""
response = self.session.put(*args, **kwargs)
Browser.add_soup(response, self.soup_config)
return response

@staticmethod
def _get_request_kwargs(method, url, **kwargs):
"""This method exists to raise a TypeError when a method or url is
Expand Down
7 changes: 7 additions & 0 deletions tests/test_browser.py
Expand Up @@ -299,6 +299,13 @@ def test_post(httpbin):
assert resp.status_code == 200 and resp.json()['form'] == data


def test_put(httpbin):
browser = mechanicalsoup.Browser()
data = {'color': 'blue', 'colorblind': 'True'}
resp = browser.put(httpbin + "/put", data)
assert resp.status_code == 200 and resp.json()['form'] == data


@pytest.mark.parametrize("http_html_expected_encoding", [
pytest.param((None, 'utf-8', 'utf-8')),
pytest.param(('utf-8', 'utf-8', 'utf-8')),
Expand Down

0 comments on commit a27ff22

Please sign in to comment.