diff --git a/setup.py b/setup.py index 3dd7d4d..56b2406 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup(name='Mastodon.py', description='Python wrapper for the Mastodon API', packages=['mastodon'], setup_requires=['pytest-runner'], - tests_require=['pytest', 'pytest-cov'], + tests_require=['pytest', 'pytest-cov', 'vcrpy', 'pytest-vcr'], install_requires=['requests', 'python-dateutil', 'six', 'pytz'], url='https://github.com/halcy/Mastodon.py', author='Lorenz Diener', diff --git a/tests/cassettes/test_date_hook.yaml b/tests/cassettes/test_date_hook.yaml new file mode 100644 index 0000000..c7ed5b5 --- /dev/null +++ b/tests/cassettes/test_date_hook.yaml @@ -0,0 +1,57 @@ +interactions: +- request: + body: visibility=&status=Toot%21 + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['26'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: '{"id":"99073771458116447","created_at":"2017-11-27T01:23:00.315Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771458116447","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771458116447","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":21},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"4fa954380935e6d530871e25dc7a45c8"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [5aa7354f-9c8d-4145-99e6-6749e8e2a1d4] + X-Runtime: ['0.088013'] + X-XSS-Protection: [1; mode=block] + content-length: ['1216'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771458116447 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"209d9274b8acc4d2f7265eb56d870053"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [5ef35962-28e8-4b0c-b5ab-51f3bdf28cce] + X-Runtime: ['0.020564'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/cassettes/test_id_hook.yaml b/tests/cassettes/test_id_hook.yaml new file mode 100644 index 0000000..77dc2e1 --- /dev/null +++ b/tests/cassettes/test_id_hook.yaml @@ -0,0 +1,57 @@ +interactions: +- request: + body: visibility=&status=Toot%21 + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['26'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: '{"id":"99073771372606324","created_at":"2017-11-27T01:22:59.008Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771372606324","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771372606324","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":20},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"2c28a9f579b2e3b51139a1081f64c227"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [c35694b9-ced1-4293-8461-e9480dc409cf] + X-Runtime: ['0.082687'] + X-XSS-Protection: [1; mode=block] + content-length: ['1216'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771372606324 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"352d49aa855575352cbfb0ba819dcde5"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [d02b01f2-185b-48a7-b338-c305d75fc7e6] + X-Runtime: ['0.024066'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/cassettes/test_id_hook_in_reply_to.yaml b/tests/cassettes/test_id_hook_in_reply_to.yaml new file mode 100644 index 0000000..ad73081 --- /dev/null +++ b/tests/cassettes/test_id_hook_in_reply_to.yaml @@ -0,0 +1,112 @@ +interactions: +- request: + body: visibility=&status=Toot%21 + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['26'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: '{"id":"99073771383398048","created_at":"2017-11-27T01:22:59.173Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771383398048","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771383398048","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":21},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"ef586888eb13661bb1965e2a7d5f19c6"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [1e79a2e1-102f-492a-9dc6-b1e6a335f027] + X-Runtime: ['0.080896'] + X-XSS-Protection: [1; mode=block] + content-length: ['1216'] + status: {code: 200, message: OK} +- request: + body: visibility=&in_reply_to_id=99073771383398048&status=Reply%21 + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['60'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: '{"id":"99073771391086384","created_at":"2017-11-27T01:22:59.292Z","in_reply_to_id":"99073771383398048","in_reply_to_account_id":"1","sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771391086384","content":"\u003cp\u003eReply!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771391086384","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":22},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"f1b126b867555c13a93a5f6a48fa2912"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [611432d3-60a5-4416-9028-1120419cd0c6] + X-Runtime: ['0.127749'] + X-XSS-Protection: [1; mode=block] + content-length: ['1231'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771391086384 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"352d49aa855575352cbfb0ba819dcde5"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [6262e8bc-2a6e-4c03-b4c9-4381f83e3a67] + X-Runtime: ['0.030844'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771383398048 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"352d49aa855575352cbfb0ba819dcde5"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [f362de58-ca39-4c4f-b89c-b2135f25a05f] + X-Runtime: ['0.028984'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/cassettes/test_id_hook_within_reblog.yaml b/tests/cassettes/test_id_hook_within_reblog.yaml new file mode 100644 index 0000000..7a4ba93 --- /dev/null +++ b/tests/cassettes/test_id_hook_within_reblog.yaml @@ -0,0 +1,115 @@ +interactions: +- request: + body: visibility=&status=Toot%21 + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['26'] + Content-Type: [application/x-www-form-urlencoded] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses + response: + body: {string: '{"id":"99073771410234489","created_at":"2017-11-27T01:22:59.589Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771410234489","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771410234489","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":22},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"a9b6db7410dca5fb876a9b990b4a7e25"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [300e401e-1f71-4e05-9f30-2ba967927abd] + X-Runtime: ['0.114153'] + X-XSS-Protection: [1; mode=block] + content-length: ['1216'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: POST + uri: http://localhost:3000/api/v1/statuses/99073771410234489/reblog + response: + body: {string: '{"id":"99073771420203780","created_at":"2017-11-27T01:22:59.736Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":null,"uri":"http://localhost:3000/users/admin/statuses/99073771420203780/activity","content":"\u003cp\u003eRT + \u003cspan class=\"h-card\"\u003e\u003ca href=\"http://localhost:3000/@admin\" + class=\"u-url mention\"\u003e@\u003cspan\u003eadmin\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e + Toot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771420203780","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":true,"muted":false,"reblog":{"id":"99073771410234489","created_at":"2017-11-27T01:22:59.589Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"http://localhost:3000/users/admin/statuses/99073771410234489","content":"\u003cp\u003eToot!\u003c/p\u003e","url":"http://localhost:3000/@admin/99073771410234489","reblogs_count":1,"favourites_count":0,"favourited":false,"reblogged":true,"muted":false,"pinned":false,"reblog":null,"application":{"name":"Mastodon.py + test suite","website":null},"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":22},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]},"application":null,"account":{"id":"1","username":"admin","acct":"admin","display_name":"codltest","locked":false,"created_at":"2017-07-01T17:09:15.621Z","note":"\u003cp\u003ehello + :)\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":23},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"85209a7d2c7cb240002817cbb8242376"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [5350fc29-7570-4f66-b296-9095100e74a7] + X-Runtime: ['0.472800'] + X-XSS-Protection: [1; mode=block] + content-length: ['2558'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771420203780 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"209d9274b8acc4d2f7265eb56d870053"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [c6c39ed1-aa7d-44b8-8a3d-ff4f2c21bb09] + X-Runtime: ['0.019955'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +- request: + body: null + headers: + Accept: ['*/*'] + Accept-Encoding: ['gzip, deflate'] + Authorization: [Bearer __MASTODON_PY_TEST_TOKEN] + Connection: [keep-alive] + Content-Length: ['0'] + User-Agent: [python-requests/2.18.4] + method: DELETE + uri: http://localhost:3000/api/v1/statuses/99073771410234489 + response: + body: {string: '{}'} + headers: + Cache-Control: ['max-age=0, private, must-revalidate'] + Content-Type: [application/json; charset=utf-8] + ETag: [W/"209d9274b8acc4d2f7265eb56d870053"] + Transfer-Encoding: [chunked] + Vary: ['Accept-Encoding, Origin'] + X-Content-Type-Options: [nosniff] + X-Frame-Options: [SAMEORIGIN] + X-Request-Id: [aaef1378-5102-4267-befe-eccdb9198429] + X-Runtime: ['0.026212'] + X-XSS-Protection: [1; mode=block] + content-length: ['2'] + status: {code: 200, message: OK} +version: 1 diff --git a/tests/fixtures.py b/tests/fixtures.py new file mode 100644 index 0000000..1b32866 --- /dev/null +++ b/tests/fixtures.py @@ -0,0 +1,25 @@ +import pytest + +@pytest.fixture +def mastodon(): + import mastodon as _mastodon + return _mastodon.Mastodon( + api_base_url='http://localhost:3000', + client_id='__MASTODON_PY_TEST_ID', + client_secret='__MASTODON_PY_TEST_SECRET', + access_token='__MASTODON_PY_TEST_TOKEN') + + + +@pytest.fixture() +def status(mastodon): + _status = mastodon.status_post('Toot!') + yield _status + mastodon.status_delete(_status['id']) + +@pytest.fixture() +def vcr_config(): + return dict( + match_on = ['method', 'path', 'query', 'body'], + decode_compressed_response = True + ) diff --git a/tests/setup_app.sql b/tests/setup_app.sql new file mode 100644 index 0000000..b9f3db9 --- /dev/null +++ b/tests/setup_app.sql @@ -0,0 +1,37 @@ +WITH new_app AS ( + INSERT INTO oauth_applications ( + name, + uid, + secret, + redirect_uri, + scopes, + owner_type, + owner_id, + created_at, + updated_at + ) VALUES ( + 'Mastodon.py test suite', + '__MASTODON_PY_TEST_ID', + '__MASTODON_PY_TEST_SECRET', + 'urn:itef:wg:oauth:2.0:oob', + 'read write follow', + 'User', + 1, + now(), + now() + ) + RETURNING id +) +INSERT INTO oauth_access_tokens ( + token, + scopes, + application_id, + resource_owner_id, + created_at +) SELECT + '__MASTODON_PY_TEST_TOKEN', + 'read write follow', + new_app.id, + 1, + now() +FROM new_app; diff --git a/tests/test_hooks.py b/tests/test_hooks.py new file mode 100644 index 0000000..fe242a6 --- /dev/null +++ b/tests/test_hooks.py @@ -0,0 +1,28 @@ +from .fixtures import * +from datetime import datetime + +@pytest.mark.vcr() +def test_id_hook(status): + assert isinstance(status['id'], int) + +@pytest.mark.vcr() +def test_id_hook_in_reply_to(mastodon, status): + reply = mastodon.status_post('Reply!', in_reply_to_id=status['id']) + try: + assert isinstance(reply['in_reply_to_id'], int) + assert isinstance(reply['in_reply_to_account_id'], int) + finally: + mastodon.status_delete(reply['id']) + +@pytest.mark.vcr() +def test_id_hook_within_reblog(mastodon, status): + reblog = mastodon.status_reblog(status['id']) + try: + assert isinstance(reblog['reblog']['id'], int) + finally: + mastodon.status_delete(reblog['id']) + + +@pytest.mark.vcr() +def test_date_hook(status): + assert isinstance(status['created_at'], datetime)