Skip to content

Commit

Permalink
feat(rpc): Added survey group ID input parameter to list_surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Dec 27, 2024
1 parent cad63d1 commit afac884
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/Added-20241226-180149.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Added
body: Added survey group ID input parameter to `list_surveys`
time: 2024-12-26T18:01:49.207724-06:00
custom:
Issue: "1242"
22 changes: 17 additions & 5 deletions src/citric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,9 +878,11 @@ def export_timeline(
survey_id,
enums.TimelineAggregationPeriod(period),
start.isoformat(),
end.isoformat()
if end
else datetime.datetime.now(tz=datetime.timezone.utc).isoformat(),
(
end.isoformat()
if end
else datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
),
)

def get_group_properties(
Expand Down Expand Up @@ -1486,20 +1488,30 @@ def list_quotas(self, survey_id: int) -> list[types.QuotaListElement]:
"""
return self.session.list_quotas(survey_id)

def list_surveys(self, username: str | None = None) -> list[dict[str, t.Any]]:
def list_surveys(
self,
username: str | None = None,
*,
survey_group_id: int | None = None,
) -> list[dict[str, t.Any]]:
"""Get all surveys or only those owned by a user.
Calls :rpc_method:`list_surveys`.
Args:
username: Owner of the surveys to retrieve.
survey_group_id: ID of the survey group to retrieve surveys from.
Returns:
List of surveys with basic information.
.. versionadded:: 0.0.1
This method.
.. versionadded:: NEXT_VERSION
The *survey_group_id* parameter.
"""
return self.session.list_surveys(username)
return self.session.list_surveys(username, survey_group_id)

def list_survey_groups(
self,
Expand Down
17 changes: 16 additions & 1 deletion tests/integration/test_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ def test_language(client: citric.Client, survey_id: int, subtests: SubTests):


@pytest.mark.integration_test
def test_survey(client: citric.Client):
def test_survey(
client: citric.Client,
server_version: semver.VersionInfo,
subtests: SubTests,
):
"""Test survey methods."""
# Try to get a survey that doesn't exist
with pytest.raises(LimeSurveyStatusError, match="Error: Invalid survey"):
Expand Down Expand Up @@ -150,6 +154,17 @@ def test_survey(client: citric.Client):
matched = next(s for s in client.list_surveys() if int(s["sid"]) == survey_id)
assert matched["surveyls_title"] == NEW_SURVEY_NAME

with subtests.test(msg="survey group ID"):
if server_version < (6, 8, 3):
pytest.xfail(
"The gsid field is not available as input nor output of the RPC "
"list_surveys method in LimeSurvey < 6.8.3"
)

gsid = matched["gsid"]
surveys_in_group = client.list_surveys(survey_group_id=gsid)
assert all(s["gsid"] == gsid for s in surveys_in_group)

# Update survey properties
response = client.set_survey_properties(
survey_id,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def test_list_groups(client: MockClient):

def test_list_surveys(client: MockClient):
"""Test list_surveys client method."""
assert_client_session_call(client, "list_surveys", None)
assert_client_session_call(client, "list_surveys", None, survey_group_id=None)


def test_list_survey_groups(client: MockClient):
Expand Down

0 comments on commit afac884

Please sign in to comment.