pymastodon/tests/test_statuses.py

68 lines
2.1 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_favourite(app):
responses.post("https://social.example.com/api/v1/statuses/1234/favourite", json=json_reader("./tests/resources/favourite_response.json"))
response = app.statuses.favourite("1234")
assert response is not None
try:
status = Status.model_validate(response)
assert status.favourited == True
except Exception as ve:
logger.debug(response)
logger.error(ve)
@responses.activate
def test_favourite(app):
responses.post("https://social.example.com/api/v1/statuses/1234/unfavourite", json=json_reader("./tests/resources/unfavourite_response.json"))
response = app.statuses.unfavourite("1234")
assert response is not None
try:
status = Status.model_validate(response)
assert status.favourited == False
except Exception as ve:
logger.debug(response)
logger.error(ve)
@responses.activate
def test_reblog(app):
responses.post("https://social.example.com/api/v1/statuses/1234/reblog", json=json_reader("./tests/resources/reblog_response.json"))
response = app.statuses.reblog("1234")
assert response is not None
try:
status = Status.model_validate(response)
assert status.reblogged == True
except Exception as ve:
logger.debug(response)
logger.error(ve)
@responses.activate
def test_unreblog(app):
responses.post("https://social.example.com/api/v1/statuses/1234/unreblog", json=json_reader("./tests/resources/unreblog_response.json"))
response = app.statuses.unreblog("1234")
assert response is not None
try:
status = Status.model_validate(response)
assert status.reblogged == False
except Exception as ve:
logger.debug(response)
logger.error(ve)
def json_reader(path):
with open(path) as f:
return json.load(f)