Add more tests

This commit is contained in:
Lorenz Diener 2018-05-06 02:26:19 +02:00
pare f34a1803a3
commit f8e209f6ff
S'han modificat 5 arxius amb 93 adicions i 2 eliminacions

Veure arxiu

@ -0,0 +1,28 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://localhost:3000/api/v1/instance/activity
response:
body: {string: '[{"week":"1525039200","statuses":"402","logins":"2","registrations":"0"},{"week":"1524434400","statuses":"0","logins":"0","registrations":"0"},{"week":"1523829600","statuses":"1514","logins":"2","registrations":"0"},{"week":"1523224800","statuses":"0","logins":"0","registrations":"0"},{"week":"1522620000","statuses":"0","logins":"0","registrations":"0"},{"week":"1522015200","statuses":"0","logins":"0","registrations":"0"},{"week":"1521414000","statuses":"0","logins":"0","registrations":"0"},{"week":"1520809200","statuses":"0","logins":"0","registrations":"0"},{"week":"1520204400","statuses":"0","logins":"0","registrations":"0"},{"week":"1519599600","statuses":"0","logins":"0","registrations":"0"},{"week":"1518994800","statuses":"0","logins":"0","registrations":"0"},{"week":"1518390000","statuses":"0","logins":"0","registrations":"0"}]'}
headers:
Cache-Control: ['max-age=86400, public']
Content-Type: [application/json; charset=utf-8]
Date: ['Sun, 06 May 2018 00:22:05 GMT']
ETag: [W/"58f08c236168987e365c17c22d5d7788"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [1155ee76-f23a-407c-a833-26e70c8efbe2]
X-Runtime: ['0.070592']
X-XSS-Protection: [1; mode=block]
content-length: ['846']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -0,0 +1,28 @@
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
Connection: [keep-alive]
User-Agent: [python-requests/2.9.1]
method: GET
uri: http://localhost:3000/api/v1/instance/peers
response:
body: {string: '[]'}
headers:
Cache-Control: ['max-age=86400, public']
Content-Type: [application/json; charset=utf-8]
Date: ['Sun, 06 May 2018 00:24:52 GMT']
ETag: [W/"3c4a13455f997cff85b40946e8a0eb9d"]
Transfer-Encoding: [chunked]
Vary: ['Accept-Encoding, Origin']
X-Content-Type-Options: [nosniff]
X-Frame-Options: [SAMEORIGIN]
X-Request-Id: [98dc4df6-9979-4d50-8473-96f9253d65b9]
X-Runtime: ['0.031372']
X-XSS-Protection: [1; mode=block]
content-length: ['2']
status: {code: 200, message: OK}
version: 1

Veure arxiu

@ -1,19 +1,23 @@
import pytest
def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN'):
def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN', version="2.3.0", version_check_mode="created"):
import mastodon
return mastodon.Mastodon(
api_base_url='http://localhost:3000',
client_id='__MASTODON_PY_TEST_CLIENT_ID',
client_secret='__MASTODON_PY_TEST_CLIENT_SECRET',
access_token=access_token,
mastodon_version="2.3.0")
mastodon_version=version,
version_check_mode=version_check_mode)
@pytest.fixture
def api():
return _api()
@pytest.fixture
def api_low_version():
return _api(version="1.2.0", version_check_mode="changed")
@pytest.fixture
def api2():

Veure arxiu

@ -1,5 +1,7 @@
import pytest
from mastodon.Mastodon import MastodonVersionError
@pytest.mark.vcr()
def test_instance(api):
instance = api.instance()
@ -8,3 +10,22 @@ def test_instance(api):
expected_keys = set(('description', 'email', 'title', 'uri', 'version', 'urls'))
assert set(instance.keys()) >= expected_keys
@pytest.mark.vcr()
def test_instance_activity(api):
activity = api.instance_activity()
assert len(activity) > 0
assert "statuses" in activity[0]
assert "logins" in activity[0]
assert "week" in activity[0]
@pytest.mark.vcr()
def test_instance_peers(api):
assert len(api.instance_peers()) == 0
@pytest.mark.vcr()
def test_low_version(api_low_version):
with pytest.raises(MastodonVersionError):
instance = api_low_version.instance()

Veure arxiu

@ -164,6 +164,16 @@ def test_invalid_event():
'',
])
def test_invalid_json():
"""But not too tolerant"""
listener = Listener()
with pytest.raises(MastodonMalformedEventError):
listener.handle_stream_([
'event: blahblah',
'data: {kjaslkdjalskdjasd asdkjhak ajdasldasd}',
'',
])
def test_missing_event_name():
listener = Listener()
with pytest.raises(MastodonMalformedEventError):