aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/cassettes/test_log_in_password.yaml26
-rw-r--r--tests/cassettes/test_log_in_password_to_file.yaml54
-rw-r--r--tests/conftest.py27
-rw-r--r--tests/setup_app.sql103
4 files changed, 133 insertions, 77 deletions
diff --git a/tests/cassettes/test_log_in_password.yaml b/tests/cassettes/test_log_in_password.yaml
index c44bed6..d220e32 100644
--- a/tests/cassettes/test_log_in_password.yaml
+++ b/tests/cassettes/test_log_in_password.yaml
@@ -1,27 +1,27 @@
1interactions: 1interactions:
2- request: 2- request:
3 body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow 3 body: !!python/unicode username=admin%40localhost%3A3000&password=mastodonadmin&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&client_id=__MASTODON_PY_TEST_CLIENT_ID&scope=read+write+follow&client_secret=__MASTODON_PY_TEST_CLIENT_SECRET&grant_type=password
4 headers: 4 headers:
5 Accept: ['*/*'] 5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate'] 6 Accept-Encoding: ['gzip, deflate']
7 Connection: [keep-alive] 7 Connection: [keep-alive]
8 Content-Length: ['221'] 8 Content-Length: ['235']
9 Content-Type: [application/x-www-form-urlencoded] 9 Content-Type: [application/x-www-form-urlencoded]
10 User-Agent: [python-requests/2.18.4] 10 User-Agent: [python-requests/2.18.4]
11 method: POST 11 method: POST
12 uri: http://localhost:3000/oauth/token 12 uri: http://localhost:3000/oauth/token
13 response: 13 response:
14 body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read 14 body: {string: !!python/unicode '{"access_token":"__MASTODON_PY_TEST_ACCESS_TOKEN_2","token_type":"bearer","scope":"read
15 write follow","created_at":1511814180}'} 15 write follow","created_at":1511992220}'}
16 headers: 16 headers:
17 Cache-Control: [no-store] 17 cache-control: [no-store]
18 Content-Type: [application/json; charset=utf-8] 18 content-length: ['126']
19 ETag: [W/"f6a22ef91276cdcde8f09c8186d2d41d"] 19 content-type: [application/json; charset=utf-8]
20 Pragma: [no-cache] 20 etag: [W/"7f19440d01a73bd9685be7280866fa5b"]
21 Transfer-Encoding: [chunked] 21 pragma: [no-cache]
22 Vary: ['Accept-Encoding, Origin'] 22 transfer-encoding: [chunked]
23 X-Request-Id: [85cb59f1-b92a-4ff8-8a49-c09bed55eb98] 23 vary: ['Accept-Encoding, Origin']
24 X-Runtime: ['0.077197'] 24 x-request-id: [d33af1b6-ae04-495f-9a8c-720b570e98a9]
25 content-length: ['117'] 25 x-runtime: ['0.244819']
26 status: {code: 200, message: OK} 26 status: {code: 200, message: OK}
27version: 1 27version: 1
diff --git a/tests/cassettes/test_log_in_password_to_file.yaml b/tests/cassettes/test_log_in_password_to_file.yaml
index f26590c..32abfdc 100644
--- a/tests/cassettes/test_log_in_password_to_file.yaml
+++ b/tests/cassettes/test_log_in_password_to_file.yaml
@@ -1,52 +1,54 @@
1interactions: 1interactions:
2- request: 2- request:
3 body: redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&password=mastodonadmin&username=admin%40localhost%3A3000&grant_type=password&client_id=__MASTODON_PY_TEST_ID&client_secret=__MASTODON_PY_TEST_SECRET&scope=read+write+follow 3 body: !!python/unicode username=admin%40localhost%3A3000&password=mastodonadmin&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&client_id=__MASTODON_PY_TEST_CLIENT_ID&scope=read+write+follow&client_secret=__MASTODON_PY_TEST_CLIENT_SECRET&grant_type=password
4 headers: 4 headers:
5 Accept: ['*/*'] 5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate'] 6 Accept-Encoding: ['gzip, deflate']
7 Connection: [keep-alive] 7 Connection: [keep-alive]
8 Content-Length: ['221'] 8 Content-Length: ['235']
9 Content-Type: [application/x-www-form-urlencoded] 9 Content-Type: [application/x-www-form-urlencoded]
10 User-Agent: [python-requests/2.18.4] 10 User-Agent: [python-requests/2.18.4]
11 method: POST 11 method: POST
12 uri: http://localhost:3000/oauth/token 12 uri: http://localhost:3000/oauth/token
13 response: 13 response:
14 body: {string: '{"access_token":"__MASTODON_PY_TEST_TOKEN","token_type":"bearer","scope":"read 14 body: {string: !!python/unicode '{"access_token":"__MASTODON_PY_TEST_ACCESS_TOKEN_2","token_type":"bearer","scope":"read
15 write follow","created_at":1511814180}'} 15 write follow","created_at":1511992220}'}
16 headers: 16 headers:
17 Cache-Control: [no-store] 17 cache-control: [no-store]
18 Content-Type: [application/json; charset=utf-8] 18 content-length: ['126']
19 ETag: [W/"f77400f50590c94b55a861fb6d432464"] 19 content-type: [application/json; charset=utf-8]
20 Pragma: [no-cache] 20 etag: [W/"d69940161df215958096efeb1a959d12"]
21 Transfer-Encoding: [chunked] 21 pragma: [no-cache]
22 Vary: ['Accept-Encoding, Origin'] 22 transfer-encoding: [chunked]
23 X-Request-Id: [b6168343-dd9e-4a0f-9ec4-69a1de8f879a] 23 vary: ['Accept-Encoding, Origin']
24 X-Runtime: ['0.080069'] 24 x-request-id: [a05d2bef-1d32-4857-97b5-6cc4136dfd29]
25 content-length: ['117'] 25 x-runtime: ['0.205660']
26 status: {code: 200, message: OK} 26 status: {code: 200, message: OK}
27- request: 27- request:
28 body: null 28 body: null
29 headers: 29 headers:
30 Accept: ['*/*'] 30 Accept: ['*/*']
31 Accept-Encoding: ['gzip, deflate'] 31 Accept-Encoding: ['gzip, deflate']
32 Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] 32 Authorization: [!!python/unicode Bearer __MASTODON_PY_TEST_ACCESS_TOKEN_2]
33 Connection: [keep-alive] 33 Connection: [keep-alive]
34 User-Agent: [python-requests/2.18.4] 34 User-Agent: [python-requests/2.18.4]
35 method: GET 35 method: GET
36 uri: http://localhost:3000/api/v1/accounts/verify_credentials 36 uri: http://localhost:3000/api/v1/accounts/verify_credentials
37 response: 37 response:
38 body: {string: '{"id":"1","username":"admin","acct":"admin","display_name":"admin","locked":false,"created_at":"2017-08-02T04:15:27.248Z","note":"\u003cp\u003e\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/69910b47243ddb47.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":2,"following_count":1,"statuses_count":16,"source":{"privacy":"public","sensitive":false,"note":""}}'} 38 body: {string: !!python/unicode '{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello
39 :)\u003c/p\u003e","url":"http://localhost:3000/@admin","avatar":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","avatar_static":"http://localhost:3000/system/accounts/avatars/000/000/001/original/99b4c443463de195.png","header":"http://localhost:3000/headers/original/missing.png","header_static":"http://localhost:3000/headers/original/missing.png","followers_count":1,"following_count":0,"statuses_count":50,"source":{"privacy":"public","sensitive":false,"note":"hello
40 :)"}}'}
39 headers: 41 headers:
40 Cache-Control: ['max-age=0, private, must-revalidate'] 42 cache-control: ['max-age=0, private, must-revalidate']
41 Content-Type: [application/json; charset=utf-8] 43 content-length: ['669']
42 ETag: [W/"622f72a29f8398775e2abff7cd51dbac"] 44 content-type: [application/json; charset=utf-8]
43 Transfer-Encoding: [chunked] 45 etag: [W/"05183e2c68a77cfb9877fc356465a322"]
44 Vary: ['Accept-Encoding, Origin'] 46 transfer-encoding: [chunked]
45 X-Content-Type-Options: [nosniff] 47 vary: ['Accept-Encoding, Origin']
46 X-Frame-Options: [SAMEORIGIN] 48 x-content-type-options: [nosniff]
47 X-Request-Id: [3852d894-50be-4342-a0e6-f9df2ddf5926] 49 x-frame-options: [SAMEORIGIN]
48 X-Runtime: ['0.029510'] 50 x-request-id: [0cdc8a2f-6deb-4437-bd96-4e7178e1b9cd]
49 X-XSS-Protection: [1; mode=block] 51 x-runtime: ['0.230997']
50 content-length: ['650'] 52 x-xss-protection: [1; mode=block]
51 status: {code: 200, message: OK} 53 status: {code: 200, message: OK}
52version: 1 54version: 1
diff --git a/tests/conftest.py b/tests/conftest.py
index a0733b5..f6ee327 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -1,21 +1,28 @@
1import pytest 1import pytest
2 2
3@pytest.fixture 3
4def api(): 4def _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN'):
5 import mastodon 5 import mastodon
6 return mastodon.Mastodon( 6 return mastodon.Mastodon(
7 api_base_url='http://localhost:3000', 7 api_base_url='http://localhost:3000',
8 client_id='__MASTODON_PY_TEST_ID', 8 client_id='__MASTODON_PY_TEST_CLIENT_ID',
9 client_secret='__MASTODON_PY_TEST_SECRET', 9 client_secret='__MASTODON_PY_TEST_CLIENT_SECRET',
10 access_token='__MASTODON_PY_TEST_TOKEN') 10 access_token=access_token)
11
12
13@pytest.fixture
14def api():
15 return _api()
16
17
18@pytest.fixture
19def api2():
20 return _api(access_token='__MASTODON_PY_TEST_ACCESS_TOKEN_2')
21
11 22
12@pytest.fixture 23@pytest.fixture
13def api_anonymous(): 24def api_anonymous():
14 import mastodon 25 return _api(access_token=None)
15 return mastodon.Mastodon(
16 api_base_url='http://localhost:3000',
17 client_id='__MASTODON_PY_TEST_ID',
18 client_secret='__MASTODON_PY_TEST_SECRET')
19 26
20@pytest.fixture() 27@pytest.fixture()
21def status(api): 28def status(api):
diff --git a/tests/setup_app.sql b/tests/setup_app.sql
index 6239eb3..81f1e18 100644
--- a/tests/setup_app.sql
+++ b/tests/setup_app.sql
@@ -1,37 +1,84 @@
1WITH new_app AS ( 1DELETE FROM oauth_access_tokens WHERE id = 6543210987654321;
2 INSERT INTO oauth_applications ( 2DELETE FROM oauth_access_tokens WHERE id = 1234567890123456;
3 name, 3DELETE FROM oauth_applications WHERE id = 1234567890123456;
4 uid, 4DELETE FROM users WHERE id = 1234567890123456;
5 secret, 5DELETE FROM accounts WHERE id = 1234567890123456;
6 redirect_uri, 6
7 scopes, 7INSERT INTO accounts (
8 owner_type, 8 id,
9 owner_id, 9 username,
10 created_at, 10 created_at,
11 updated_at 11 updated_at
12 ) VALUES ( 12) VALUES (
13 'Mastodon.py test suite', 13 1234567890123456,
14 '__MASTODON_PY_TEST_ID', 14 'mastodonpy_test',
15 '__MASTODON_PY_TEST_SECRET', 15 now(),
16 'urn:ietf:wg:oauth:2.0:oob', 16 now()
17 'read write follow', 17);
18 'User', 18
19 1, 19INSERT INTO users (
20 now(), 20 id,
21 now() 21 email,
22 ) 22 account_id,
23 RETURNING id 23 created_at,
24) 24 updated_at,
25 confirmed_at,
26 locale
27) VALUES (
28 1234567890123456,
29 'mastodonpy_test@localhost:3000',
30 1234567890123456,
31 now(),
32 now(),
33 now(),
34 'ja' -- japanese locale for unicode testing :p
35);
36
37
38
39INSERT INTO oauth_applications (
40 id,
41 name,
42 uid,
43 secret,
44 redirect_uri,
45 scopes,
46 owner_type,
47 owner_id,
48 created_at,
49 updated_at
50) VALUES (
51 1234567890123456,
52 'Mastodon.py test suite',
53 '__MASTODON_PY_TEST_CLIENT_ID',
54 '__MASTODON_PY_TEST_CLIENT_SECRET',
55 'urn:ietf:wg:oauth:2.0:oob',
56 'read write follow',
57 'User',
58 1234567890123456,
59 now(),
60 now()
61);
62
25INSERT INTO oauth_access_tokens ( 63INSERT INTO oauth_access_tokens (
64 id,
26 token, 65 token,
27 scopes, 66 scopes,
28 application_id, 67 application_id,
29 resource_owner_id, 68 resource_owner_id,
30 created_at 69 created_at
31) SELECT 70) VALUES (
32 '__MASTODON_PY_TEST_TOKEN', 71 1234567890123456,
72 '__MASTODON_PY_TEST_ACCESS_TOKEN',
73 'read write follow',
74 1234567890123456,
75 1234567890123456,
76 now()
77), (
78 6543210987654321,
79 '__MASTODON_PY_TEST_ACCESS_TOKEN_2',
33 'read write follow', 80 'read write follow',
34 new_app.id, 81 1234567890123456,
35 1, 82 1,
36 now() 83 now()
37FROM new_app; 84);
Powered by cgit v1.2.3 (git 2.41.0)