import pytest import pdb from datetime import datetime, timezone from .fixtures.config import config_fixture from .fixtures.client import client_fixture as client_fixture from .fixtures.db import session_fixture, engine_fixture from sqlmodel import select from diyalgo.models import Status @pytest.mark.parametrize('status_str', ['My test status']) def test_status_text(client_fixture, session_fixture, status_str): posted = client_fixture.status_post(status_str) status = Status(**posted) with session_fixture as session: session.add(status) session.commit() # compare to committed status status = session.exec(select(Status).where(Status.id == posted['id'])).first() # model uses account_id instead of full account object posted['account_id'] = posted['account']['id'] for k, v in status.dict().items(): # text is a special case that's only relevant when the status has been deleted: # https://docs.joinmastodon.org/entities/Status/#text if k in ('text', 'account'): continue # we gain utc timezone for datetimes if isinstance(v, datetime): assert v == posted[k].replace(tzinfo=None) else: assert v == posted[k] # if __name__ == "__main__": # from diyalgo.client.init import log_in # from diyalgo import models # from diyalgo.db import init_db_engine, create_tables # from sqlmodel import Session # # client = log_in() # posted = client.status_post('hey my status') # status = models.Status(**posted) # # engine = init_db_engine() # create_tables(engine) # session = Session(engine) # # session.add(status) # session.commit() # # posted2 = client.status_post('hey my status again') # status2 = models.Status(**posted2) # session.add(status2) # session.commit()