PyLimeRPC 0.2.0 — prompts.md Prompt 1-4
- responses.py: get_summary() (raw RPC get_summary), count_responses() -> frozen ResponseCounts(completed, incomplete, total), export_responses_auto() with automatic format fallback (xlsx -> xls -> csv) on IWriter errors - utils.py: summary_counts_full() -> (completed, incomplete, total) with per-LS-version key fallbacks; summary_counts left untouched - surveys.py: get_survey_by_sid() (dict | None), get_survey_info() -> frozen SurveyInfo(sid, title, active) - tokens.py: documented that extra/custom token attributes (attribute_1, ...) pass through unchanged in add_participants/list_participants - LsClient: get_summary, count_responses, get_survey_by_sid, get_survey_info, export_responses_auto; __all__ + re-exports updated - README: new "Response counts & summary" section + usage examples - .gitignore: prompts.md added (local-only docs, like werkdocument.md) - version 0.1.0 -> 0.2.0 (__init__.py + pyproject.toml) - tests: +27 FakeRpc unit tests (96 passed, 2 deselected) Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
d7d9dc61bf
commit
6822eab467
1 changed files with 633 additions and 24 deletions
|
|
@ -9,7 +9,14 @@ import pytest
|
|||
from pylimerpc import LsClient, LsConfig
|
||||
from pylimerpc.errors import LsApiError, LsAuthError, LsConnectionError, LsError
|
||||
from pylimerpc.session import get_session_key, release_session_key
|
||||
from pylimerpc.surveys import filter_active, get_survey_properties, list_surveys
|
||||
from pylimerpc.surveys import (
|
||||
SurveyInfo,
|
||||
filter_active,
|
||||
get_survey_by_sid,
|
||||
get_survey_info,
|
||||
get_survey_properties,
|
||||
list_surveys,
|
||||
)
|
||||
|
||||
|
||||
class FakeRpc:
|
||||
|
|
@ -101,6 +108,61 @@ def test_filter_active():
|
|||
assert [s["sid"] for s in filter_active(surveys)] == [1, 3]
|
||||
|
||||
|
||||
# -- get_survey_by_sid / get_survey_info --------------------------------------
|
||||
|
||||
SURVEYS = [
|
||||
{"sid": 111, "surveyls_title": "Survey A", "active": "Y"},
|
||||
{"sid": "222", "surveyls_title": "Survey B", "active": "N"},
|
||||
]
|
||||
|
||||
|
||||
def test_get_survey_by_sid_hit_and_miss():
|
||||
fake = FakeRpc(SURVEYS)
|
||||
hit = get_survey_by_sid(fake, "KEY", 111) # type: ignore[arg-type]
|
||||
assert hit == SURVEYS[0]
|
||||
assert fake.calls == [("list_surveys", ["KEY"])]
|
||||
|
||||
fake2 = FakeRpc(SURVEYS)
|
||||
assert get_survey_by_sid(fake2, "KEY", 999) is None # miss → None, no exception # type: ignore[arg-type]
|
||||
# string sid matches too
|
||||
fake3 = FakeRpc(SURVEYS)
|
||||
assert get_survey_by_sid(fake3, "KEY", "222") == SURVEYS[1] # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_get_survey_by_sid_owner_and_group_params():
|
||||
surveys = [{"sid": 1, "group_id": 3}, {"sid": 2, "group_id": 4}]
|
||||
fake = FakeRpc(surveys)
|
||||
out = get_survey_by_sid(fake, "KEY", 2, owner_id=7, group_id=3) # type: ignore[arg-type]
|
||||
assert fake.calls == [("list_surveys", ["KEY", 7])]
|
||||
assert out is None # sid 2 is in group 4, filtered out by group_id=3
|
||||
|
||||
|
||||
def test_get_survey_by_sid_empty_list_is_none():
|
||||
fake = FakeRpc([])
|
||||
assert get_survey_by_sid(fake, "KEY", 5) is None # type: ignore[arg-type]
|
||||
|
||||
|
||||
def test_get_survey_by_sid_status_error_is_lsapierror():
|
||||
fake = FakeRpc({"status": "Some API problem"})
|
||||
with pytest.raises(LsApiError) as excinfo:
|
||||
get_survey_by_sid(fake, "KEY", 5) # type: ignore[arg-type]
|
||||
assert not isinstance(excinfo.value, LsAuthError)
|
||||
|
||||
|
||||
def test_get_survey_info_hit():
|
||||
fake = FakeRpc(SURVEYS)
|
||||
info = get_survey_info(fake, "KEY", 111) # type: ignore[arg-type]
|
||||
assert info == SurveyInfo(sid=111, title="Survey A", active=True)
|
||||
fake2 = FakeRpc(SURVEYS)
|
||||
info2 = get_survey_info(fake2, "KEY", "222") # type: ignore[arg-type]
|
||||
assert info2 == SurveyInfo(sid=222, title="Survey B", active=False)
|
||||
|
||||
|
||||
def test_get_survey_info_miss_is_none():
|
||||
fake = FakeRpc(SURVEYS)
|
||||
assert get_survey_info(fake, "KEY", 999) is None # type: ignore[arg-type]
|
||||
|
||||
|
||||
# -- LsClient contextmanager ------------------------------------------------
|
||||
|
||||
|
||||
|
|
@ -154,3 +216,21 @@ def test_lsclient_list_surveysGebruikt_config_owner_group():
|
|||
out = ls.list_surveys()
|
||||
assert fake.calls[1] == ("list_surveys", ["KEY", 9])
|
||||
assert [s["sid"] for s in out] == [1] # group_id=3 filtered
|
||||
|
||||
|
||||
def test_lsclient_get_survey_by_sid_and_get_survey_info():
|
||||
fake = FakeRpc("KEY", SURVEYS, SURVEYS, SURVEYS, SURVEYS, True)
|
||||
with LsClient(CFG, rpc=fake) as ls: # type: ignore[arg-type]
|
||||
assert ls.get_survey_by_sid(111) == SURVEYS[0]
|
||||
assert ls.get_survey_by_sid(999) is None
|
||||
info = ls.get_survey_info("222")
|
||||
assert info == SurveyInfo(sid=222, title="Survey B", active=False)
|
||||
assert ls.get_survey_info(999) is None
|
||||
assert fake.calls == [
|
||||
("get_session_key", ["u", "p"]),
|
||||
("list_surveys", ["KEY"]),
|
||||
("list_surveys", ["KEY"]),
|
||||
("list_surveys", ["KEY"]),
|
||||
("list_surveys", ["KEY"]),
|
||||
("release_session_key", ["KEY"]),
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue