Mastodon.py/tests
halcy 5f09c3814e Fix an issue, remove a test 2022-11-15 11:10:13 +02:00
..
cassettes Improve auth support 2022-11-13 22:32:04 +02:00
cassettes_old_pagination
cassettes_pre_2_9_2
cassettes_pre_4_0_0 add media v2 API + tests, move v1 test 2022-11-08 23:24:42 +02:00
README.markdown add thumbnail customization support 2022-11-13 13:14:34 +02:00
__init__.py
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
setup.sql Fix tests 2022-11-11 00:21:00 +02:00
test_account.py Add support and tests for "notifying" follow 2022-11-13 16:02:34 +02:00
test_admin.py Fix some things in streaming and admin API for 3.3.0 support 2022-11-13 18:39:56 +02:00
test_auth.py Improve auth support 2022-11-13 22:32:04 +02:00
test_blurhash.py
test_bookmarks.py Introduces pagin parameters for bookmarks 2022-06-24 15:46:27 +02:00
test_constructor.py
test_create_app.py Fixed overseen test failure with new app name in "secret" file 2022-06-28 13:22:06 +02:00
test_domain_blocks.py
test_errors.py
test_filters.py Initial test fixing pass. Four tests still fail. 2022-11-07 23:11:30 +02: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
test_instance.py Add, test and document profile directory API (fixes #188) 2019-10-12 22:05:35 +02:00
test_lists.py
test_markers.py Add, test and document last-read markers. Fixes #192 2019-10-12 22:55:17 +02:00
test_media.py clean up media loading, add thumbnail to media_update 2022-11-13 14:06:50 +02:00
test_notifications.py Add support and tests for "notifying" follow 2022-11-13 16:02:34 +02:00
test_pagination.py Preserves storage of pagination in items for compatibility reason 2022-06-24 17:23:00 +02:00
test_polls.py
test_push.py
test_reports.py
test_search.py
test_status.py
test_streaming.py Fix an issue, remove a test 2022-11-15 11:10:13 +02:00
test_timeline.py Initial test fixing pass. Four tests still fail. 2022-11-07 23:11:30 +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, with the default admin user and default password. To set this up, follow the development guide and set up the database using "rails db:setup".

It also needs various things to be set up for it. The following command should 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.

import pytest

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