Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added name and description parameters to import_group #1153

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/unreleased/Added-20240528-231314.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: Added
body: Added `name` and `description` parameters to `import_group`
time: 2024-05-28T23:13:14.913661-06:00
custom:
Issue: "1153"
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ jobs:
context: https://github.com/martialblog/docker-limesurvey.git#master:6.0/apache
database: postgres

- python-version: "3.12"
ref: refs/pull/3860/head
context: https://github.com/martialblog/docker-limesurvey.git#master:6.0/apache
database: postgres

steps:
- name: Check out the repository
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
Expand Down
16 changes: 14 additions & 2 deletions src/citric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,30 +1231,42 @@ def import_group(
file: t.IO[bytes],
survey_id: int,
file_type: str | enums.ImportGroupType = "lsg",
*,
name: str | None = None,
description: str | None = None,
) -> int:
"""Import group from a file.

Create a new group from an exported LSG file.

TODO: Check support for custom name and description.

Calls :rpc_method:`import_group`.

Args:
file: File object.
survey_id: The ID of the Survey that the question will belong to.
file_type: Type of file. One of LSS, CSV, TXT and LSA.
name: Optional new name for the group.
description: Optional new description for the group.

Returns:
The ID of the new group.

.. code-block:: python

with open("group.lsg", "rb") as f:
group_id = client.import_group(f, survey_id)

.. versionadded:: 0.0.10
.. versionchanged:: NEXT_VERSION
Added the ``name`` and ``description`` optional parameters.
"""
contents = base64.b64encode(file.read()).decode()
return self.session.import_group(
survey_id,
contents,
enums.ImportGroupType(file_type),
name,
description,
)

def import_question(
Expand Down
22 changes: 22 additions & 0 deletions tests/integration/test_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,28 @@
client.get_group_properties(survey_id)


@pytest.mark.integration_test
@pytest.mark.xfail_mysql(strict=True)
def test_import_group_with_name(client: citric.Client, survey_id: int):
"""Test importing a group with a custom name."""
with Path("./examples/group.lsg").open("rb") as f:
group_id = client.import_group(f, survey_id, name="Custom Name")

group_props = client.get_group_properties(group_id)
assert group_props["group_name"] == "Custom Name"

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / 5-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.8 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.9 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.10 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.11 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.13 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration pypy3.10 / 6-apache / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / refs/heads/develop / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group

Check failure on line 261 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / refs/heads/master / postgres

test_import_group_with_name AssertionError: assert 'First Group' == 'Custom Name' - Custom Name + First Group


@pytest.mark.integration_test
@pytest.mark.xfail_mysql(strict=True)
def test_import_group_with_description(client: citric.Client, survey_id: int):
"""Test importing a group with a custom description."""
with Path("./examples/group.lsg").open("rb") as f:
group_id = client.import_group(f, survey_id, description="Custom description")

group_props = client.get_group_properties(group_id)
assert group_props["description"] == "Custom description"

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / 5-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.8 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.9 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.10 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.11 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.13 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration pypy3.10 / 6-apache / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / refs/heads/develop / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>

Check failure on line 272 in tests/integration/test_rpc_client.py

View workflow job for this annotation

GitHub Actions / integration 3.12 / refs/heads/master / postgres

test_import_group_with_description AssertionError: assert '<p>A new group</p>' == 'Custom description' - Custom description + <p>A new group</p>


@pytest.mark.integration_test
def test_question(client: citric.Client, survey_id: int):
"""Test question methods."""
Expand Down
Loading