Mastodon.py/tests
halcy 02d38084ea Add Terms of Service 2025-08-17 23:43:12 +03:00
..
cassettes add new featured tags endpoints 2025-08-17 23:07:09 +03:00
cassettes_entity_tests Add Terms of Service 2025-08-17 23:43:12 +03:00
cassettes_old_pagination
cassettes_pre_2_9_2
cassettes_pre_4_0_0
cassettes_pre_4_4_0 add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
cassettes_special
README.markdown
__init__.py
amewatson.jpg
conftest.py add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
image.jpg
setup.sql make test setup work on 4.4.3, add delete_media to status_delete 2025-08-17 20:17:10 +03:00
test_account.py add new featured tags endpoints 2025-08-17 23:07:09 +03:00
test_admin.py
test_auth.py add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
test_blurhash.py
test_bookmarks.py
test_constructor.py
test_create_app.py
test_domain_blocks.py
test_entities.py Add Terms of Service 2025-08-17 23:43:12 +03:00
test_errors.py
test_filters.py
test_follow_requests.py
test_hooks.py
test_instance.py
test_lists.py
test_markers.py
test_media.py
test_notifications.py add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
test_pagination.py
test_polls.py
test_push.py
test_reports.py
test_search.py
test_status.py add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
test_status_length.py
test_streaming.py
test_timeline.py
test_trends.py
test_zzz_revoke.py add endorsement endpoints, tests ran against 4.4.0 2025-08-17 22:47:43 +03:00
video.mp4

README.markdown

Running

To run this test suite, install the testing dependencies:

pip install -e .[test,webpush,blurhash]

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"