File: test_errors.py

package info (click to toggle)
python-mastodon 2.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,836 kB
  • sloc: python: 9,438; makefile: 206; sql: 98; sh: 27
file content (39 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import pytest
import vcr
from mastodon.Mastodon import MastodonAPIError
import json
from mastodon.return_types import Status, try_cast_recurse
try:
    from mock import MagicMock
except ImportError:
    from unittest.mock import MagicMock

def test_nonstandard_errors(api):
    response = MagicMock()
    response.json = MagicMock(return_value="I am a non-standard instance and this error is a plain string.")
    response.ok = False
    response.status_code = 501
    session = MagicMock()
    session.request = MagicMock(return_value=response)

    api.session = session
    with pytest.raises(MastodonAPIError):
        api.instance()

@pytest.mark.vcr()
def test_lang_for_errors(api):
    try:
        api.status_post("look at me i am funny shark gawr gura: " + "a" * 50000)
    except Exception as e:
        e1 = str(e)
    api.set_language("de")
    try:
        api.status_post("look at me i am funny shark gawr gura: " + "a" * 50000)
    except Exception as e:
        e2 = str(e)
    assert e1 != e2

def test_broken_date(api):
    dict1 = try_cast_recurse(Status, json.loads('{"uri":"icosahedron.website", "created_at": "", "edited_at": "2012-09-27"}'))
    assert "edited_at" in dict1
    assert dict1.created_at is None