Mastodonplus.py/tests/test_errors.py

22 líneas
571 B
Python
Original Vista normal Històric

2019-03-11 14:50:23 +01:00
import pytest
from mastodon.Mastodon import MastodonAPIError
2019-04-15 14:31:41 +02:00
2019-03-11 14:50:23 +01:00
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
2019-06-22 15:28:27 +02:00
response.status_code = 501
2019-03-11 14:50:23 +01:00
session = MagicMock()
session.request = MagicMock(return_value=response)
api.session = session
with pytest.raises(MastodonAPIError):
api.instance()