mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-21 12:44:27 +00:00
Try to fix tests
This commit is contained in:
parent
626a165411
commit
f4c70096e2
4 changed files with 38 additions and 11 deletions
24
app/main.py
24
app/main.py
|
@ -443,6 +443,28 @@ def outbox_by_public_id(
|
|||
|
||||
replies_tree = boxes.get_replies_tree(db, maybe_object)
|
||||
|
||||
likes = (
|
||||
db.query(models.InboxObject)
|
||||
.filter(
|
||||
models.InboxObject.ap_type == "Like",
|
||||
models.InboxObject.activity_object_ap_id == maybe_object.ap_id,
|
||||
)
|
||||
.options(joinedload(models.InboxObject.actor))
|
||||
.order_by(models.InboxObject.ap_published_at.desc())
|
||||
.limit(10)
|
||||
)
|
||||
|
||||
shares = (
|
||||
db.query(models.InboxObject)
|
||||
.filter(
|
||||
models.InboxObject.ap_type == "Announce",
|
||||
models.InboxObject.activity_object_ap_id == maybe_object.ap_id,
|
||||
)
|
||||
.options(joinedload(models.InboxObject.actor))
|
||||
.order_by(models.InboxObject.ap_published_at.desc())
|
||||
.limit(10)
|
||||
)
|
||||
|
||||
return templates.render_template(
|
||||
db,
|
||||
request,
|
||||
|
@ -450,6 +472,8 @@ def outbox_by_public_id(
|
|||
{
|
||||
"replies_tree": replies_tree,
|
||||
"outbox_object": maybe_object,
|
||||
"likes": likes,
|
||||
"shares": shares,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
@ -58,14 +58,14 @@ class InboxObject(Base, BaseObject):
|
|||
is_hidden_from_stream = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
ap_actor_id = Column(String, nullable=False)
|
||||
ap_type = Column(String, nullable=False)
|
||||
ap_type = Column(String, nullable=False, index=True)
|
||||
ap_id = Column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = Column(String, nullable=True)
|
||||
ap_published_at = Column(DateTime(timezone=True), nullable=False)
|
||||
ap_object: Mapped[ap.RawObject] = Column(JSON, nullable=False)
|
||||
|
||||
# Only set for activities
|
||||
activity_object_ap_id = Column(String, nullable=True)
|
||||
activity_object_ap_id = Column(String, nullable=True, index=True)
|
||||
|
||||
visibility = Column(Enum(ap.VisibilityEnum), nullable=False)
|
||||
|
||||
|
@ -134,12 +134,12 @@ class OutboxObject(Base, BaseObject):
|
|||
|
||||
public_id = Column(String, nullable=False, index=True)
|
||||
|
||||
ap_type = Column(String, nullable=False)
|
||||
ap_type = Column(String, nullable=False, index=True)
|
||||
ap_id = Column(String, nullable=False, unique=True, index=True)
|
||||
ap_context = Column(String, nullable=True)
|
||||
ap_object: Mapped[ap.RawObject] = Column(JSON, nullable=False)
|
||||
|
||||
activity_object_ap_id = Column(String, nullable=True)
|
||||
activity_object_ap_id = Column(String, nullable=True, index=True)
|
||||
|
||||
# Source content for activities (like Notes)
|
||||
source = Column(String, nullable=True)
|
||||
|
|
|
@ -11,5 +11,6 @@ debug = true
|
|||
|
||||
# In-mem DB
|
||||
sqlalchemy_database_url = "sqlite:///file:pytest?mode=memory&cache=shared&uri=true"
|
||||
# sqlalchemy_database_url = "sqlite:///data/pytest.db"
|
||||
key_path = "tests/test.key"
|
||||
media_db_path = "tests/media.db"
|
||||
|
|
|
@ -8,22 +8,24 @@ from app.database import Base
|
|||
from app.database import engine
|
||||
from app.database import get_db
|
||||
from app.main import app
|
||||
from tests.factories import _Session
|
||||
|
||||
_Session = orm.sessionmaker(bind=engine, autocommit=False, autoflush=False)
|
||||
# _Session = orm.sessionmaker(bind=engine, autocommit=False, autoflush=False)
|
||||
|
||||
|
||||
def _get_db_for_testing() -> Generator[orm.Session, None, None]:
|
||||
session = _Session()
|
||||
try:
|
||||
yield session
|
||||
finally:
|
||||
session.close()
|
||||
# try:
|
||||
yield _Session # type: ignore
|
||||
# finally:
|
||||
# session.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db() -> Generator:
|
||||
Base.metadata.create_all(bind=engine)
|
||||
yield orm.scoped_session(orm.sessionmaker(bind=engine))
|
||||
# sess = orm.sessionmaker(bind=engine)()
|
||||
yield _Session
|
||||
# yield orm.scoped_session(orm.sessionmaker(bind=engine))
|
||||
try:
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
except Exception:
|
||||
|
|
Loading…
Reference in a new issue