pymastodon/tests/test_timelines.py

98 lines
3.3 KiB
Python
Raw Permalink Normal View History

2024-04-30 08:42:20 +02:00
from mastodon.application import MastodonApplication
from mastodon.timelines import Timelines
from mastodon.model.status import Status
from loguru import logger
import json
2024-04-30 08:42:20 +02:00
import pytest
from responses import matchers
import responses
2024-04-30 08:42:20 +02:00
@pytest.fixture
def app():
yield MastodonApplication("pymastodon")
@responses.activate
2024-04-30 08:42:20 +02:00
def test_home_timeline(app):
responses.get("https://social.example.com/api/v1/timelines/home", json=json_reader("./tests/resources/timeline_home_response.json"))
2024-04-30 08:42:20 +02:00
response = app.timelines.home_timeline()
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_timeline(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_timeline(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_timeline(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_timeline(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)
#match=[matchers.query_param_matcher(params)],