pymastodon/tests/test_timelines.py

96 lines
3.2 KiB
Python
Raw 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-05-02 12:37:16 +02:00
response = app.timelines.home()
2024-04-30 08:42:20 +02:00
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)])
2024-05-02 12:37:16 +02:00
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)])
2024-05-02 12:37:16 +02:00
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)])
2024-05-02 12:37:16 +02:00
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)])
2024-05-02 12:37:16 +02:00
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)