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: implement add_language in client #207

Merged
merged 1 commit into from
Feb 8, 2022
Merged
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
2 changes: 1 addition & 1 deletion docs/api_coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| `activate_survey` | Yes | Activate survey (RPC function) |
| `activate_tokens` | Yes | Activate survey participants (RPC function) |
| `add_group` | Yes | Add empty group with minimum details (RPC function) |
| `add_language` | No | Add a survey language (RPC function) |
| `add_language` | Yes | Add a survey language (RPC function) |
| `add_participants` | Yes | Add participants to the survey. |
| `add_response` | Yes | Add a response to the survey responses collection. |
| `add_survey` | No | Add an empty survey with minimum details |
Expand Down
13 changes: 13 additions & 0 deletions src/citric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ def activate_tokens(
"""
return self.__session.activate_tokens(survey_id)

def add_language(self, survey_id: int, language: str) -> dict[str, Any]:
"""Add a survey language.

Args:
survey_id: ID of the Survey for which a language will be added.
language: A valid language shortcut to add to the current Survey. If the
language already exists no error will be given.

Returns:
Status message.
"""
return self.__session.add_language(survey_id, language)

def add_participants(
self,
survey_id: int,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def test_add_group(client: MockClient):
)


def test_add_language(client: MockClient):
"""Test add_language client method."""
assert_client_session_call(client, "add_language", 1, "ru")


def test_copy_survey(client: MockClient):
"""Test copy_survey client method."""
assert_client_session_call(client, "copy_survey", 1, "New Survey")
Expand Down
12 changes: 11 additions & 1 deletion tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,23 @@ def client() -> Generator[citric.Client, None, None]:
def survey_id(client: citric.Client) -> Generator[int, None, None]:
"""Import a survey from a file and return its ID."""
with open("./examples/survey.lss", "rb") as f:
survey_id = client.import_survey(f)
survey_id = client.import_survey(f, survey_id=98765)

yield survey_id

client.delete_survey(survey_id)


@pytest.mark.integration_test
def test_add_language(client: citric.Client, survey_id: int):
"""Test adding a new language to a survey."""
client.add_language(survey_id, "es")
client.add_language(survey_id, "ru")

survey_props = client.get_survey_properties(survey_id)
assert survey_props["additional_languages"] == "es ru"


@pytest.mark.integration_test
def test_import_group(client: citric.Client, survey_id: int):
"""Test importing a group from an lsg file."""
Expand Down