Skip to content

Commit

Permalink
test: Dedup some variables used in tests (#1056)
Browse files Browse the repository at this point in the history
* test: Dedup some variables used in tests

* Merge tests

* Revert "Merge tests"

This reverts commit 00ef7e1.
  • Loading branch information
edgarrmondragon authored Dec 16, 2023
1 parent 3362cf5 commit 0598dbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/integration/test_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def test_site_settings(client: citric.Client):
def test_missing_setting(client: citric.Client):
"""Test getting site settings."""
with pytest.raises(LimeSurveyStatusError, match="Invalid setting"):
assert client._get_site_setting("not_a_valid_setting")
client._get_site_setting("not_a_valid_setting")


@pytest.mark.integration_test
Expand Down
13 changes: 7 additions & 6 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def randbytes(n: int) -> bytes: # noqa: D103
NEW_GROUP_ID = 300
NEW_QUESTION_ID = 400
NEW_SURVEY_NAME = "New Survey"
DUMMY_FILE_CONTENTS = b"FILE CONTENTS"


class MockSession(Session):
Expand Down Expand Up @@ -101,15 +102,15 @@ def add_response(self, *args: t.Any) -> str:

def export_responses(self, *args: t.Any) -> bytes:
"""Mock responses file content."""
return base64.b64encode(b"FILE CONTENTS")
return base64.b64encode(DUMMY_FILE_CONTENTS)

def export_responses_by_token(self, *args: t.Any) -> bytes:
"""Mock responses file content."""
return base64.b64encode(b"FILE CONTENTS")
return base64.b64encode(DUMMY_FILE_CONTENTS)

def export_statistics(self, *args: t.Any) -> bytes:
"""Mock statistics file content."""
return base64.b64encode(b"FILE CONTENTS")
return base64.b64encode(DUMMY_FILE_CONTENTS)

def export_timeline(self, *args: t.Any) -> dict[str, int]:
"""Mock submission timeline."""
Expand Down Expand Up @@ -491,18 +492,18 @@ def test_save_responses(client: MockClient, tmpdir: LocalPath):
"""Test export_responses and export_responses_by_token client methods."""
filename = tmpdir / "responses.csv"
client.save_responses(filename, 1, file_format="csv")
assert filename.read_binary() == b"FILE CONTENTS"
assert filename.read_binary() == DUMMY_FILE_CONTENTS

filename_token = tmpdir / "responses_token.csv"
client.save_responses(filename_token, 1, token="123abc", file_format="csv")
assert filename_token.read_binary() == b"FILE CONTENTS"
assert filename_token.read_binary() == DUMMY_FILE_CONTENTS


def test_save_statistics(client: MockClient, tmpdir: LocalPath):
"""Test save_statistics and export_responses_by_token client methods."""
filename = tmpdir / "example.html"
client.save_statistics(filename, 1, file_format="html")
assert filename.read_binary() == b"FILE CONTENTS"
assert filename.read_binary() == DUMMY_FILE_CONTENTS


def test_download_files(client: MockClient, tmp_path: Path):
Expand Down

0 comments on commit 0598dbc

Please sign in to comment.