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
|
2024-05-01 20:41:01 +02:00
|
|
|
import json
|
2024-04-30 08:42:20 +02:00
|
|
|
import pytest
|
2024-05-01 20:41:01 +02:00
|
|
|
from responses import matchers
|
|
|
|
import responses
|
2024-04-30 08:42:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def app():
|
|
|
|
yield MastodonApplication("pymastodon")
|
|
|
|
|
2024-05-01 20:41:01 +02:00
|
|
|
@responses.activate
|
2024-04-30 08:42:20 +02:00
|
|
|
def test_home_timeline(app):
|
2024-05-01 20:41:01 +02:00
|
|
|
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)
|
2024-05-01 20:41:01 +02:00
|
|
|
|
|
|
|
@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")
|
2024-05-01 20:41:01 +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_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")
|
2024-05-01 20:41:01 +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_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")
|
2024-05-01 20:41:01 +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_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")
|
2024-05-01 20:41:01 +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)
|
|
|
|
|
|
|
|
|
|
|
|
def json_reader(path):
|
|
|
|
with open(path) as f:
|
|
|
|
return json.load(f)
|