aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-05-06 02:26:19 +0200
committerLorenz Diener <[email protected]>2018-05-06 02:26:19 +0200
commitf8e209f6ff70d3be08b71b05f4cec753a9dac926 (patch)
tree01d8c51afadb49350b2fde718f2a5cb1351b2d2f /tests
parentf34a1803a398a94f1231345145140291cd699398 (diff)
downloadmastodon.py-f8e209f6ff70d3be08b71b05f4cec753a9dac926.tar.gz
Add more tests
Diffstat (limited to 'tests')
-rw-r--r--tests/cassettes/test_instance_activity.yaml28
-rw-r--r--tests/cassettes/test_instance_peers.yaml28
-rw-r--r--tests/conftest.py8
-rw-r--r--tests/test_instance.py21
-rw-r--r--tests/test_streaming.py10
5 files changed, 93 insertions, 2 deletions
diff --git a/tests/cassettes/test_instance_activity.yaml b/tests/cassettes/test_instance_activity.yaml
new file mode 100644
index 0000000..f981c19
--- /dev/null
+++ b/tests/cassettes/test_instance_activity.yaml
@@ -0,0 +1,28 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.9.1]
10 method: GET
11 uri: http://localhost:3000/api/v1/instance/activity
12 response:
13 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"}]'}
14 headers:
15 Cache-Control: ['max-age=86400, public']
16 Content-Type: [application/json; charset=utf-8]
17 Date: ['Sun, 06 May 2018 00:22:05 GMT']
18 ETag: [W/"58f08c236168987e365c17c22d5d7788"]
19 Transfer-Encoding: [chunked]
20 Vary: ['Accept-Encoding, Origin']
21 X-Content-Type-Options: [nosniff]
22 X-Frame-Options: [SAMEORIGIN]
23 X-Request-Id: [1155ee76-f23a-407c-a833-26e70c8efbe2]
24 X-Runtime: ['0.070592']
25 X-XSS-Protection: [1; mode=block]
26 content-length: ['846']
27 status: {code: 200, message: OK}
28version: 1
diff --git a/tests/cassettes/test_instance_peers.yaml b/tests/cassettes/test_instance_peers.yaml
new file mode 100644
index 0000000..0f70fc0
--- /dev/null
+++ b/tests/cassettes/test_instance_peers.yaml
@@ -0,0 +1,28 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.9.1]
10 method: GET
11 uri: http://localhost:3000/api/v1/instance/peers
12 response:
13 body: {string: '[]'}
14 headers:
15 Cache-Control: ['max-age=86400, public']
16 Content-Type: [application/json; charset=utf-8]
17 Date: ['Sun, 06 May 2018 00:24:52 GMT']
18 ETag: [W/"3c4a13455f997cff85b40946e8a0eb9d"]
19 Transfer-Encoding: [chunked]
20 Vary: ['Accept-Encoding, Origin']
21 X-Content-Type-Options: [nosniff]
22 X-Frame-Options: [SAMEORIGIN]
23 X-Request-Id: [98dc4df6-9979-4d50-8473-96f9253d65b9]
24 X-Runtime: ['0.031372']
25 X-XSS-Protection: [1; mode=block]
26 content-length: ['2']
27 status: {code: 200, message: OK}
28version: 1
diff --git a/tests/conftest.py b/tests/conftest.py
index b1fc8c5..a1dc161 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,19 +1,23 @@
1import pytest 1import pytest
2 2
3def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN'): 3def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN', version="2.3.0", version_check_mode="created"):
4 import mastodon 4 import mastodon
5 return mastodon.Mastodon( 5 return mastodon.Mastodon(
6 api_base_url='http://localhost:3000', 6 api_base_url='http://localhost:3000',
7 client_id='__MASTODON_PY_TEST_CLIENT_ID', 7 client_id='__MASTODON_PY_TEST_CLIENT_ID',
8 client_secret='__MASTODON_PY_TEST_CLIENT_SECRET', 8 client_secret='__MASTODON_PY_TEST_CLIENT_SECRET',
9 access_token=access_token, 9 access_token=access_token,
10 mastodon_version="2.3.0") 10 mastodon_version=version,
11 version_check_mode=version_check_mode)
11 12
12 13
13@pytest.fixture 14@pytest.fixture
14def api(): 15def api():
15 return _api() 16 return _api()
16 17
18@pytest.fixture
19def api_low_version():
20 return _api(version="1.2.0", version_check_mode="changed")
17 21
18@pytest.fixture 22@pytest.fixture
19def api2(): 23def api2():
diff --git a/tests/test_instance.py b/tests/test_instance.py
index 7b6dc49..e8be86f 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -1,5 +1,7 @@
1import pytest 1import pytest
2 2
3from mastodon.Mastodon import MastodonVersionError
4
3@pytest.mark.vcr() 5@pytest.mark.vcr()
4def test_instance(api): 6def test_instance(api):
5 instance = api.instance() 7 instance = api.instance()
@@ -8,3 +10,22 @@ def test_instance(api):
8 10
9 expected_keys = set(('description', 'email', 'title', 'uri', 'version', 'urls')) 11 expected_keys = set(('description', 'email', 'title', 'uri', 'version', 'urls'))
10 assert set(instance.keys()) >= expected_keys 12 assert set(instance.keys()) >= expected_keys
13
14@pytest.mark.vcr()
15def test_instance_activity(api):
16 activity = api.instance_activity()
17
18 assert len(activity) > 0
19 assert "statuses" in activity[0]
20 assert "logins" in activity[0]
21 assert "week" in activity[0]
22
23@pytest.mark.vcr()
24def test_instance_peers(api):
25 assert len(api.instance_peers()) == 0
26
27@pytest.mark.vcr()
28def test_low_version(api_low_version):
29 with pytest.raises(MastodonVersionError):
30 instance = api_low_version.instance()
31 \ No newline at end of file
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index 883b773..33d1381 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -164,6 +164,16 @@ def test_invalid_event():
164 '', 164 '',
165 ]) 165 ])
166 166
167def test_invalid_json():
168 """But not too tolerant"""
169 listener = Listener()
170 with pytest.raises(MastodonMalformedEventError):
171 listener.handle_stream_([
172 'event: blahblah',
173 'data: {kjaslkdjalskdjasd asdkjhak ajdasldasd}',
174 '',
175 ])
176
167def test_missing_event_name(): 177def test_missing_event_name():
168 listener = Listener() 178 listener = Listener()
169 with pytest.raises(MastodonMalformedEventError): 179 with pytest.raises(MastodonMalformedEventError):
Powered by cgit v1.2.3 (git 2.41.0)