|
| 1 | +from pingpong import models |
| 2 | +import pingpong.schemas as schemas |
| 3 | + |
| 4 | +from .testutil import with_authz, with_institution, with_user |
| 5 | + |
| 6 | + |
| 7 | +@with_user(123) |
| 8 | +@with_institution(1, "Test Institution") |
| 9 | +@with_authz( |
| 10 | + grants=[ |
| 11 | + ("user:123", "can_edit", "assistant:1"), |
| 12 | + ("user:123", "can_share_assistants", "class:1"), |
| 13 | + ] |
| 14 | +) |
| 15 | +async def test_unshare_assistant_revokes_share_without_lazy_loading( |
| 16 | + api, db, institution, valid_user_token |
| 17 | +): |
| 18 | + async with db.async_session() as session: |
| 19 | + creator = models.User(email="creator@test.org") |
| 20 | + session.add(creator) |
| 21 | + await session.flush() |
| 22 | + |
| 23 | + class_ = models.Class( |
| 24 | + id=1, |
| 25 | + name="Test Class", |
| 26 | + institution_id=institution.id, |
| 27 | + ) |
| 28 | + session.add(class_) |
| 29 | + await session.flush() |
| 30 | + |
| 31 | + assistant = models.Assistant( |
| 32 | + id=1, |
| 33 | + name="Test Assistant", |
| 34 | + instructions="Test instructions", |
| 35 | + description="Test description", |
| 36 | + interaction_mode=schemas.InteractionMode.CHAT, |
| 37 | + model="gpt-4o-mini", |
| 38 | + temperature=0.2, |
| 39 | + class_id=class_.id, |
| 40 | + tools="[]", |
| 41 | + creator_id=creator.id, |
| 42 | + published=None, |
| 43 | + version=3, |
| 44 | + ) |
| 45 | + session.add(assistant) |
| 46 | + await session.flush() |
| 47 | + |
| 48 | + share_link = await models.AnonymousLink.create( |
| 49 | + session, |
| 50 | + share_token="share-token-123", |
| 51 | + assistant_id=assistant.id, |
| 52 | + ) |
| 53 | + await session.commit() |
| 54 | + |
| 55 | + response = api.delete( |
| 56 | + f"/api/v1/class/{class_.id}/assistant/{assistant.id}/share/{share_link.id}", |
| 57 | + headers={"Authorization": f"Bearer {valid_user_token}"}, |
| 58 | + ) |
| 59 | + assert response.status_code == 200 |
| 60 | + assert response.json() == {"status": "ok"} |
| 61 | + |
| 62 | + async with db.async_session() as session: |
| 63 | + updated_share_link = await models.AnonymousLink.get_by_id( |
| 64 | + session, share_link.id |
| 65 | + ) |
| 66 | + assert updated_share_link.active is False |
| 67 | + assert updated_share_link.revoked_at is not None |
0 commit comments