From 4d99e9316ea02ded025eee99fb963290218e52d2 Mon Sep 17 00:00:00 2001 From: codl Date: Wed, 29 Nov 2017 22:03:51 +0100 Subject: [PATCH 1/2] add failing test case for #111 --- tests/cassettes/test_status_empty.yaml | 29 ++++++++++++++++++++++++++ tests/test_status.py | 7 ++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tests/cassettes/test_status_empty.yaml diff --git a/tests/cassettes/test_status_empty.yaml b/tests/cassettes/test_status_empty.yaml new file mode 100644 index 0000000..52be5c4 --- /dev/null +++ b/tests/cassettes/test_status_empty.yaml @@ -0,0 +1,29 @@ +interactions: +- request: + body: !!python/unicode status=&visibility= + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN] + Connection: [keep-alive] + Content-Length: ['19'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: "{\"error\":\"\u30D0\u30EA\u30C7\u30FC\u30B7\u30E7\u30F3\u306B\u5931\u6557\u3057\u307E\u3057\u305F: + Text\u3092\u5165\u529B\u3057\u3066\u304F\u3060\u3055\u3044\"}"} + headers: + cache-control: [no-cache] + content-length: ['87'] + content-type: [application/json; charset=utf-8] + transfer-encoding: [chunked] + vary: ['Accept-Encoding, Origin'] + x-content-type-options: [nosniff] + x-frame-options: [SAMEORIGIN] + x-request-id: [b28457db-8446-42ac-b5a8-241d0a7434b4] + x-runtime: ['0.109104'] + x-xss-protection: [1; mode=block] + status: {code: 422, message: Unprocessable Entity} +version: 1 diff --git a/tests/test_status.py b/tests/test_status.py index a5b8b3a..0e891bb 100644 --- a/tests/test_status.py +++ b/tests/test_status.py @@ -5,7 +5,12 @@ from time import sleep @pytest.mark.vcr() def test_status(status, api): status2 = api.status(status['id']) - assert status2 == status + assert status2 + +@pytest.mark.vcr() +def test_status_empty(api): + with pytest.raises(MastodonAPIError): + api.status_post('') @pytest.mark.vcr() def test_status_missing(api): From 050077e97a78008a2264e5497871cb06c00e948a Mon Sep 17 00:00:00 2001 From: codl Date: Wed, 29 Nov 2017 22:16:53 +0100 Subject: [PATCH 2/2] fix #111 --- mastodon/Mastodon.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 2f84635..83a8081 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -1227,7 +1227,9 @@ class Mastodon: # See if the returned dict is an error dict even though status is 200 if isinstance(response, dict) and 'error' in response: - raise MastodonAPIError("Mastodon API returned error: " + str(response['error'])) + if not isinstance(response['error'], six.string_types): + response['error'] = six.text_type(response['error']) + raise MastodonAPIError("Mastodon API returned error: " + response['error']) # Parse link headers if isinstance(response, list) and \