diff options
author | micah <[email protected]> | 2022-11-25 16:39:10 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2022-11-25 16:39:10 -0500 |
commit | 99514e50d1e1ef6330397c2cada203dfa3891b3a (patch) | |
tree | cbac11da3a71a24bbb739d9aa8fda65bc7968dd4 /tests/test_errors.py | |
parent | 5d7ca19c30dc6579bf29610fe815b822889978e6 (diff) | |
parent | 10b2a9984237aaae6a512d441001e635060d6af7 (diff) | |
download | mastodon.py-99514e50d1e1ef6330397c2cada203dfa3891b3a.tar.gz |
Merge pull request #1 from halcy/master
pull in upstream
Diffstat (limited to 'tests/test_errors.py')
-rw-r--r-- | tests/test_errors.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/tests/test_errors.py b/tests/test_errors.py index 5c13d04..ca11c42 100644 --- a/tests/test_errors.py +++ b/tests/test_errors.py | |||
@@ -1,5 +1,7 @@ | |||
1 | import pytest | 1 | import pytest |
2 | import vcr | ||
2 | from mastodon.Mastodon import MastodonAPIError | 3 | from mastodon.Mastodon import MastodonAPIError |
4 | import json | ||
3 | 5 | ||
4 | try: | 6 | try: |
5 | from mock import MagicMock | 7 | from mock import MagicMock |
@@ -8,8 +10,7 @@ except ImportError: | |||
8 | 10 | ||
9 | def test_nonstandard_errors(api): | 11 | def test_nonstandard_errors(api): |
10 | response = MagicMock() | 12 | response = MagicMock() |
11 | response.json = MagicMock(return_value= | 13 | response.json = MagicMock(return_value="I am a non-standard instance and this error is a plain string.") |
12 | "I am a non-standard instance and this error is a plain string.") | ||
13 | response.ok = False | 14 | response.ok = False |
14 | response.status_code = 501 | 15 | response.status_code = 501 |
15 | session = MagicMock() | 16 | session = MagicMock() |
@@ -19,3 +20,23 @@ def test_nonstandard_errors(api): | |||
19 | with pytest.raises(MastodonAPIError): | 20 | with pytest.raises(MastodonAPIError): |
20 | api.instance() | 21 | api.instance() |
21 | 22 | ||
23 | @pytest.mark.vcr() | ||
24 | def test_lang_for_errors(api): | ||
25 | try: | ||
26 | api.status_post("look at me i am funny shark gawr gura: " + "a" * 50000) | ||
27 | except Exception as e: | ||
28 | e1 = str(e) | ||
29 | api.set_language("de") | ||
30 | try: | ||
31 | api.status_post("look at me i am funny shark gawr gura: " + "a" * 50000) | ||
32 | except Exception as e: | ||
33 | e2 = str(e) | ||
34 | assert e1 != e2 | ||
35 | |||
36 | def test_broken_date(api): | ||
37 | dict1 = json.loads('{"uri":"icosahedron.website", "created_at": "", "edited_at": "2012-09-27"}', object_hook=api._Mastodon__json_hooks) | ||
38 | dict2 = json.loads('{"uri":"icosahedron.website", "created_at": "2012-09-27", "subfield": {"edited_at": "null"}}', object_hook=api._Mastodon__json_hooks) | ||
39 | assert "edited_at" in dict1 | ||
40 | assert not "created_at" in dict1 | ||
41 | assert "created_at" in dict2 | ||
42 | assert not "edited_at" in dict2.subfield | ||