Skip to content

Commit daba4fd

Browse files
test: Update tests according to new changes.
1 parent 72e5e0d commit daba4fd

File tree

4 files changed

+32
-50
lines changed

4 files changed

+32
-50
lines changed

tests/cli/test_run.py

+29-31
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
398398

399399
# This is default base path to use
400400
zuliprc_path = os.path.join(str(tmp_path), path_to_use)
401+
zuliprc_file = os.path.join(zuliprc_path, "zuliprc")
401402
monkeypatch.setenv("HOME", zuliprc_path)
402403

403404
# Give some arbitrary input and fake that it's always valid
@@ -412,12 +413,18 @@ def test_main_cannot_write_zuliprc_given_good_credentials(
412413
captured = capsys.readouterr()
413414
lines = captured.out.strip().split("\n")
414415

415-
expected_line = (
416-
"\x1b[91m"
417-
f"{expected_exception}: zuliprc could not be created "
418-
f"at {os.path.join(zuliprc_path, 'zuliprc')}"
419-
"\x1b[0m"
420-
)
416+
if expected_exception == "FileNotFoundError":
417+
expected_error = (
418+
f"could not create {zuliprc_file} "
419+
f"([Errno 2] No such file or directory: '{zuliprc_file}')"
420+
)
421+
else: # PermissionError
422+
expected_error = (
423+
f"could not create {zuliprc_file} "
424+
f"([Errno 13] Permission denied: '{zuliprc_file}')"
425+
)
426+
427+
expected_line = f"\x1b[91m{expected_exception}: {expected_error}\x1b[0m"
421428
assert lines[-1] == expected_line
422429

423430

@@ -573,38 +580,29 @@ def test_exit_with_error(
573580
def test__write_zuliprc__success(
574581
tmp_path: Path, id: str = "id", key: str = "key", url: str = "url"
575582
) -> None:
576-
path = os.path.join(str(tmp_path), "zuliprc")
577-
578-
error_message = _write_zuliprc(path, server_url=url, login_id=id)
583+
"""Test successful creation of zuliprc and zulip_key files."""
584+
path = tmp_path / "zuliprc"
585+
key_path = tmp_path / "zulip_key"
586+
587+
error_message = _write_zuliprc(
588+
to_path=str(path),
589+
key_path=str(key_path),
590+
login_id=id,
591+
api_key=key,
592+
server_url=url,
593+
)
579594

580595
assert error_message == ""
581596

582-
expected_contents = (
583-
f"[api]\nemail={id}\n"
584-
f"# Fill the passcmd field with a command that outputs the API key.\n"
585-
f"# The API key is temporarily stored in the 'zulip_key' file at "
586-
f"{os.path.dirname(os.path.abspath(path))}."
587-
f"\n# After storing the key in a password manager, replace the cmd.\n"
588-
f"passcmd=cat zulip_key\nsite={url}"
589-
)
597+
expected_contents = f"[api]\nemail={id}\npasscmd=cat zulip_key\nsite={url}"
590598
with open(path) as f:
591599
assert f.read() == expected_contents
592600

593-
assert stat.filemode(os.stat(path).st_mode)[-6:] == 6 * "-"
594-
601+
with open(key_path) as f:
602+
assert f.read() == key
595603

596-
def test__write_zuliprc__fail_file_exists(
597-
minimal_zuliprc: str,
598-
tmp_path: Path,
599-
id: str = "id",
600-
key: str = "key",
601-
url: str = "url",
602-
) -> None:
603-
path = os.path.join(str(tmp_path), "zuliprc")
604-
605-
error_message = _write_zuliprc(path, server_url=url, login_id=id)
606-
607-
assert error_message == "zuliprc already exists at " + path
604+
assert stat.filemode(os.stat(path).st_mode)[-6:] == 6 * "-"
605+
assert stat.filemode(os.stat(key_path).st_mode)[-6:] == "------"
608606

609607

610608
@pytest.mark.parametrize(

tests/conftest.py

-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
keys_for_command,
1818
primary_key_for_command,
1919
)
20-
from zulipterminal.core import Controller
2120
from zulipterminal.helper import (
2221
CustomProfileData,
2322
Index,
@@ -53,11 +52,6 @@ def no_asynch(mocker: MockerFixture) -> None:
5352
mocker.patch("zulipterminal.helper.asynch")
5453

5554

56-
@pytest.fixture(autouse=True)
57-
def dummy_api_key(monkeypatch: pytest.MonkeyPatch) -> None:
58-
monkeypatch.setattr(Controller, "get_api_key", lambda self, value: "dummy_api_key")
59-
60-
6155
# --------------- Controller Fixtures -----------------------------------------
6256

6357

tests/core/test_core.py

-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ def controller(self, mocker: MockerFixture) -> Controller:
4343
)
4444

4545
# Mock get_api_key to return a dummy value
46-
mocker.patch.object(Controller, "get_api_key", return_value="dummy_api_key")
4746

4847
self.config_file = "path/to/zuliprc"
4948
self.theme_name = "zt_dark"
@@ -83,7 +82,6 @@ def test_initialize_controller(
8382
self.client.assert_called_once_with(
8483
config_file=self.config_file,
8584
client="ZulipTerminal/" + ZT_VERSION + " " + platform(),
86-
api_key="dummy_api_key", # Add this line
8785
)
8886
self.model.assert_called_once_with(controller)
8987
self.view.assert_called_once_with(controller)

tests/platform_code/test_platform_code.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@pytest.mark.parametrize(
1717
"platform, is_notification_sent",
1818
[
19+
# platform: Literal["WSL", "MacOS", "Linux", "unsupported"]
1920
pytest.param(
2021
"WSL",
2122
True,
@@ -71,6 +72,8 @@ def test_notify_quotes(
7172
assert len(params) == 1 # One external run call
7273
assert len(params[0][0][0]) == cmd_length
7374

75+
# NOTE: If there is a quoting error, we may get a ValueError too
76+
7477

7578
@pytest.mark.parametrize(
7679
"platform, expected_return_code",
@@ -105,14 +108,3 @@ def test_normalized_file_path(
105108
) -> None:
106109
mocker.patch(MODULE + ".PLATFORM", platform)
107110
assert normalized_file_path(path) == expected_path
108-
109-
110-
@pytest.mark.parametrize("button_count", [1, 2, 3]) # Add parameterization
111-
def test_button_selection(mocker: MockerFixture, button_count: int) -> None:
112-
"""Test button selection in popups."""
113-
buttons = [mocker.Mock(selected=False) for _ in range(button_count)]
114-
buttons[0].selected = True # Select the first button by default
115-
116-
assert any(
117-
button.selected for button in buttons
118-
), "At least one button should be selected"

0 commit comments

Comments
 (0)