Mastodon.py/tests
halcy 0f775f5fe1 fix #398 and also fix pagination info not surviving persisting 2025-03-02 11:13:35 +02:00
..
cassettes fix #398 and also fix pagination info not surviving persisting 2025-03-02 11:13:35 +02:00
cassettes_entity_tests add new entity tests 2025-02-15 22:05:25 +02:00
cassettes_old_pagination
cassettes_pre_2_9_2
cassettes_pre_4_0_0
cassettes_special
README.markdown move webpush and blurhash deps out of test deps 2023-04-25 14:18:36 +02:00
__init__.py
amewatson.jpg
conftest.py fix #398 and also fix pagination info not surviving persisting 2025-03-02 11:13:35 +02:00
image.jpg
setup.sql Fix every test, lets see what CI thinks of this 2025-02-13 23:35:34 +02:00
test_account.py add avatar/header delete 2025-02-14 23:45:52 +02:00
test_admin.py IP Blocks, fix some things 2025-02-15 18:20:27 +02:00
test_admin_trends.yaml mystery 2025-02-15 18:05:58 +02:00
test_auth.py test update 2025-02-14 00:10:49 +02:00
test_blurhash.py move webpush and blurhash deps out of test deps 2023-04-25 14:18:36 +02:00
test_bookmarks.py
test_constructor.py Add v2 admin accounts API 2022-11-28 00:55:41 +02:00
test_create_app.py Fix every test, lets see what CI thinks of this 2025-02-13 23:35:34 +02:00
test_domain_blocks.py
test_entities.py add new entity tests 2025-02-15 22:05:25 +02:00
test_errors.py nice up some things, fix tests (maybe) 2025-02-14 01:34:02 +02:00
test_filters.py add v2 filters 2025-02-15 21:54:08 +02:00
test_follow_requests.py
test_hooks.py Add many, many tests, and fix bugs found while adding them. also serialization. 2025-02-14 20:08:00 +02:00
test_instance.py add instance languages support 2025-02-15 20:15:28 +02:00
test_lists.py refactor: replace lambdas with python 2022-12-03 22:04:26 +01:00
test_markers.py maybe tests are green now? 2023-06-23 23:16:44 +03:00
test_media.py
test_notifications.py add grouped notifications 2025-02-15 21:06:27 +02:00
test_pagination.py fix #398 and also fix pagination info not surviving persisting 2025-03-02 11:13:35 +02:00
test_polls.py
test_push.py move webpush and blurhash deps out of test deps 2023-04-25 14:18:36 +02:00
test_reports.py
test_search.py skip 2.9.2 on 3.10 upwards since json broke somehow 2023-06-24 01:56:19 +03:00
test_status.py translation support 2025-02-15 17:27:04 +02:00
test_streaming.py Fix every test, lets see what CI thinks of this 2025-02-13 23:35:34 +02:00
test_timeline.py add link timeline, update suggestions 2025-02-14 23:33:26 +02:00
test_trends.py
test_zzz_revoke.py test update 2025-02-14 00:10:49 +02: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"