Mastodon.py/tests
Miroslav Šedivý 325cc917d5 refactor: use f-strings 2022-12-02 22:04:23 +01:00
..
cassettes commit new set of tests 2022-12-01 22:07:42 +02:00
cassettes_old_pagination Implement, document and test pagination changes 2019-04-27 23:11:37 +02:00
cassettes_pre_2_9_2 Update tests for 3.0.1 and fix regressions 2019-10-11 23:59:24 +02:00
cassettes_pre_4_0_0 add media v2 API + tests, move v1 test 2022-11-08 23:24:42 +02:00
cassettes_special some more tests 2022-11-19 00:15:54 +02:00
README.markdown Restructure the docs, a lot 2022-11-29 00:50:02 +02:00
__init__.py not pep8 compliant #71 2017-09-05 22:59:32 +02:00
amewatson.jpg add media v2 API + tests, move v1 test 2022-11-08 23:24:42 +02:00
conftest.py fix naming for featured tags 2022-11-13 14:54:23 +02:00
image.jpg add tests for media 2017-11-27 23:49:14 +01:00
setup.sql add admin stats APIs 2022-11-27 02:43:22 +02:00
test_account.py Add remove_from_followers 2022-11-27 23:55:26 +02:00
test_admin.py Add v2 admin accounts API 2022-11-28 00:55:41 +02:00
test_auth.py Add admin trends test 2022-11-25 00:01:07 +02:00
test_blurhash.py Add previously forgotten test 2019-05-11 01:22:55 +02:00
test_bookmarks.py refactor: use is for True/False 2022-11-20 20:22:48 +01:00
test_constructor.py Add v2 admin accounts API 2022-11-28 00:55:41 +02:00
test_create_app.py refactor: use f-strings 2022-12-02 22:04:23 +01:00
test_domain_blocks.py add tests for domain block methods 2017-11-30 01:29:20 +01:00
test_errors.py add lang parameter 2022-11-25 01:48:49 +02:00
test_filters.py refactor: use is for True/False 2022-11-20 20:22:48 +01:00
test_follow_requests.py Add support for timed mutes, fix tests to actually pass with new setup 2022-11-13 15:33:10 +02:00
test_hooks.py refactor: use is for None 2022-11-20 20:14:25 +01:00
test_instance.py reapply accidentally reverted changes 2022-11-30 19:28:42 +02:00
test_lists.py New casettes, small fixes 2018-06-05 22:10:31 +02:00
test_markers.py Add, test and document last-read markers. Fixes #192 2019-10-12 22:55:17 +02:00
test_media.py Add new notification types, test for pathlib support 2022-11-24 00:59:48 +02:00
test_notifications.py Add notification tests 2022-11-24 01:53:34 +02:00
test_pagination.py refactor: use f-strings 2022-12-02 22:04:23 +01:00
test_polls.py Improve own_votes test 2019-10-12 19:57:14 +02:00
test_push.py refactor: use is for True/False 2022-11-20 20:22:48 +01:00
test_reports.py Test fixups and small 2.8 fixes 2019-04-27 21:04:06 +02:00
test_search.py Add new parameter for search 2019-10-12 20:13:38 +02:00
test_status.py refactor: use f-strings 2022-12-02 22:04:23 +01:00
test_streaming.py Fix some tests, fix a pleroma specific date parsing issue 2022-11-22 01:30:43 +02:00
test_timeline.py refactor: use is for True/False 2022-11-20 20:22:48 +01:00
test_trends.py Add trending APIs 2022-11-24 22:56:49 +02:00
video.mp4 add media v2 API + tests, move v1 test 2022-11-08 23:24:42 +02:00

README.markdown

Running

To run this test suite, install the testing dependencies:

pip install -e .[test]

Then, run pytest.

If you wish to check test coverage:

pytest --cov=mastodon

And if you want a complete HTML coverage report:

pytest --cov=mastodon --cov-report html:coverage
# then open coverage/index.html in your favourite web browser

Note that some tests are slightly unstable, as they require sidekiq to do things at the right time, and will thus sometimes break.

Contributing

This test suite uses VCR.py to record requests to Mastodon and replay them in successive runs.

If you want to add or change tests, you will need a Mastodon development server running on http://localhost:3000. To set this up, follow the development guide at https://docs.joinmastodon.org/dev/setup/ .

It also needs various things to be set up for it. The following command will do the trick:

sudo redis-cli flushall && sleep 3 && \
sudo /etc/init.d/redis-server restart && \
RAILS_ENV=development rails db:setup && \
RAILS_ENV=development bin/tootctl accounts create admin2 --email zerocool@example.com --confirmed --role Owner && \
RAILS_ENV=development bin/tootctl accounts create mastodonpy_test --email mastodonpy_test@localhost:3000 --confirmed && \
RAILS_ENV=development bin/tootctl accounts create mastodonpy_test_2 --email mastodonpy_test_2@localhost:3000 --confirmed && \
psql -d mastodon_development < ~/masto/Mastodon.py/tests/setup.sql && sleep 4 && \
RAILS_ENV=development DB_PASS="" foreman start

You may additionally have to set up a database password and pass it as DB_PASS for the streaming tests to function.

Tests that send requests to Mastodon should be marked as needing VCR with the pytest.mark.vcr decorator. Streaming tests use a heavily monkeypatched version of VCR.py to work and may behave in weird ways sometimes.

import pytest

@pytest.mark.vcr()
def test_fun_new_feature(api):
    foo = api.fun_new_feature()
    assert foo = "bar"