pymastodon/tests/test_timelines.py

96 lines
3.2 KiB
Python

from mastodon.application import MastodonApplication
from mastodon.timelines import Timelines
from mastodon.model.status import Status
from loguru import logger
import json
import pytest
from responses import matchers
import responses
@pytest.fixture
def app():
yield MastodonApplication("pymastodon")
@responses.activate
def test_home_timeline(app):
responses.get("https://social.example.com/api/v1/timelines/home", json=json_reader("./tests/resources/timeline_home_response.json"))
response = app.timelines.home()
assert response is not None
statuses = []
for status in response:
try:
statuses.append(Status.model_validate(status))
except Exception as ve:
logger.debug(status)
logger.error(ve)
@responses.activate
def test_home_timeline_max_id(app):
params = {"max_id": "1"}
responses.get("https://social.example.com/api/v1/timelines/home",
json=json_reader("./tests/resources/timeline_home_response.json"),
match=[matchers.query_param_matcher(params)])
response = app.timelines.home(max_id="1")
assert response is not None
statuses = []
for status in response:
try:
statuses.append(Status.model_validate(status))
except Exception as ve:
logger.debug(status)
logger.error(ve)
@responses.activate
def test_home_timeline_min_id(app):
params = {"min_id": "1"}
responses.get("https://social.example.com/api/v1/timelines/home",
json=json_reader("./tests/resources/timeline_home_response.json"),
match=[matchers.query_param_matcher(params)])
response = app.timelines.home(min_id="1")
assert response is not None
statuses = []
for status in response:
try:
statuses.append(Status.model_validate(status))
except Exception as ve:
logger.debug(status)
logger.error(ve)
@responses.activate
def test_home_timeline_since_id(app):
params = {"since_id": "1"}
responses.get("https://social.example.com/api/v1/timelines/home",
json=json_reader("./tests/resources/timeline_home_response.json"),
match=[matchers.query_param_matcher(params)])
response = app.timelines.home(since_id="1")
assert response is not None
statuses = []
for status in response:
try:
statuses.append(Status.model_validate(status))
except Exception as ve:
logger.debug(status)
logger.error(ve)
@responses.activate
def test_home_timeline_limt(app):
params = {"limit": "1"}
responses.get("https://social.example.com/api/v1/timelines/home",
json=json_reader("./tests/resources/timeline_home_response.json"),
match=[matchers.query_param_matcher(params)])
response = app.timelines.home(limit="1")
assert response is not None
statuses = []
for status in response:
try:
statuses.append(Status.model_validate(status))
except Exception as ve:
logger.debug(status)
logger.error(ve)
def json_reader(path):
with open(path) as f:
return json.load(f)