|
25 | 25 | validate_saved_prompt_name, |
26 | 26 | validate_saved_prompt_quota, |
27 | 27 | ) |
| 28 | +from utils.suid import get_suid |
28 | 29 |
|
29 | 30 |
|
30 | 31 | @pytest.fixture(name="sqlite_engine") |
@@ -60,6 +61,11 @@ def patch_saved_prompts_get_session_fixture( |
60 | 61 | ) |
61 | 62 |
|
62 | 63 | def _get_session() -> Session: |
| 64 | + """Create a Session bound to the in-memory test engine. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + Session: A new SQLAlchemy session for patched DAL calls. |
| 68 | + """ |
63 | 69 | return session_factory() |
64 | 70 |
|
65 | 71 | mocker.patch("utils.saved_prompts.get_session", side_effect=_get_session) |
@@ -330,6 +336,32 @@ def test_list_returns_only_that_users_prompts_ordered_by_created_at_desc( |
330 | 336 | assert [p.id for p in results] == [newer.id, older.id] |
331 | 337 | assert all(p.user_id == "user-1" for p in results) |
332 | 338 |
|
| 339 | + def test_list_caps_at_configured_upper_bound( |
| 340 | + self, mocker: MockerFixture, sqlite_engine: Engine |
| 341 | + ) -> None: |
| 342 | + """Test list applies SAVED_PROMPTS_MAX_PER_USER_UPPER_BOUND as a hard cap.""" |
| 343 | + mocker.patch( |
| 344 | + "utils.saved_prompts.constants.SAVED_PROMPTS_MAX_PER_USER_UPPER_BOUND", |
| 345 | + 2, |
| 346 | + ) |
| 347 | + session_factory = sessionmaker( |
| 348 | + autocommit=False, autoflush=False, bind=sqlite_engine |
| 349 | + ) |
| 350 | + with session_factory() as session: |
| 351 | + for index in range(3): |
| 352 | + session.add( |
| 353 | + SavedPrompt( |
| 354 | + id=get_suid(), |
| 355 | + user_id="user-1", |
| 356 | + name=f"prompt-{index}", |
| 357 | + content=f"content-{index}", |
| 358 | + ) |
| 359 | + ) |
| 360 | + session.commit() |
| 361 | + |
| 362 | + results = list_saved_prompts_by_user("user-1") |
| 363 | + assert len(results) == 2 |
| 364 | + |
333 | 365 |
|
334 | 366 | @pytest.mark.usefixtures("patch_saved_prompts_get_session") |
335 | 367 | class TestDeleteSavedPromptByIdAndUser: |
|
0 commit comments