From 16da166ee1759a7c329645b3fae3c433856a90f6 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Fri, 2 Sep 2022 23:47:23 +0200 Subject: [PATCH] Tweak queries in tests --- tests/test_actor.py | 2 +- tests/test_inbox.py | 2 +- tests/test_outbox.py | 26 +++++++++++++------------- tests/test_tags.py | 3 ++- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/tests/test_actor.py b/tests/test_actor.py index c59f2c0..587b1b4 100644 --- a/tests/test_actor.py +++ b/tests/test_actor.py @@ -52,4 +52,4 @@ def test_sqlalchemy_factory(db: Session) -> None: ap_actor=ra.ap_actor, ap_id=ra.ap_id, ) - assert actor_in_db.id == db.query(models.Actor).one().id + assert actor_in_db.id == db.execute(select(models.Actor)).scalar_one().id diff --git a/tests/test_inbox.py b/tests/test_inbox.py index 41b6463..48db11c 100644 --- a/tests/test_inbox.py +++ b/tests/test_inbox.py @@ -75,7 +75,7 @@ def test_inbox_incoming_follow_request( assert inbox_object.ap_object == follow_activity.ap_object # And a follower was internally created - follower = db.query(models.Follower).one() + follower = db.execute(select(models.Follower)).scalar_one() assert follower.ap_actor_id == ra.ap_id assert follower.actor_id == saved_actor.id assert follower.inbox_object_id == inbox_object.id diff --git a/tests/test_outbox.py b/tests/test_outbox.py index 9a3bef7..cb0ac70 100644 --- a/tests/test_outbox.py +++ b/tests/test_outbox.py @@ -53,12 +53,12 @@ def test_send_follow_request( assert response.headers.get("Location") == "http://testserver/" # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Follow" assert outbox_object.activity_object_ap_id == ra.ap_id # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == ra.inbox_url @@ -111,7 +111,7 @@ def test_send_delete__reverts_side_effects( assert outbox_object.activity_object_ap_id == outbox_note.ap_id # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == ra.inbox_url @@ -144,11 +144,11 @@ def test_send_create_activity__no_followers_and_with_mention( assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Note" # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == ra.inbox_url @@ -180,11 +180,11 @@ def test_send_create_activity__with_followers( assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Note" # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == follower.actor.inbox_url @@ -220,7 +220,7 @@ def test_send_create_activity__question__one_of( assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Question" assert outbox_object.is_one_of_poll is True assert len(outbox_object.poll_items) == 2 @@ -228,7 +228,7 @@ def test_send_create_activity__question__one_of( assert outbox_object.is_poll_ended is False # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == follower.actor.inbox_url @@ -266,7 +266,7 @@ def test_send_create_activity__question__any_of( assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Question" assert outbox_object.is_one_of_poll is False assert len(outbox_object.poll_items) == 4 @@ -274,7 +274,7 @@ def test_send_create_activity__question__any_of( assert outbox_object.is_poll_ended is False # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == follower.actor.inbox_url @@ -307,11 +307,11 @@ def test_send_create_activity__article( assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Article" assert outbox_object.ap_object["name"] == "Article" # And an outgoing activity was queued - outgoing_activity = db.query(models.OutgoingActivity).one() + outgoing_activity = db.execute(select(models.OutgoingActivity)).scalar_one() assert outgoing_activity.outbox_object_id == outbox_object.id assert outgoing_activity.recipient == follower.actor.inbox_url diff --git a/tests/test_tags.py b/tests/test_tags.py index 6c3967b..d3b4ce5 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -1,4 +1,5 @@ from fastapi.testclient import TestClient +from sqlalchemy import select from sqlalchemy.orm import Session from app import activitypub as ap @@ -35,7 +36,7 @@ def test_tags__note_with_tag(db: Session, client: TestClient) -> None: assert response.status_code == 302 # And the Follow activity was created in the outbox - outbox_object = db.query(models.OutboxObject).one() + outbox_object = db.execute(select(models.OutboxObject)).scalar_one() assert outbox_object.ap_type == "Note" assert len(outbox_object.tags) == 1 emoji_tag = outbox_object.tags[0]