Skip to content

Commit a1132b8

Browse files
docs: Update README to explain passcmd usage in zuliprc.
1 parent 6da7b0d commit a1132b8

File tree

12 files changed

+1692
-200
lines changed

12 files changed

+1692
-200
lines changed

README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ to get the hang of things.
207207

208208
## Configuration
209209

210+
configuration conssist of two file:
211+
- zulip_key, file contains the api_key
212+
- zuliprc, file consist of login configurations
213+
214+
The `zulip_key`contains only the api_key.
215+
210216
The `zuliprc` file contains two sections:
211217
- an `[api]` section with information required to connect to your Zulip server
212218
- a `[zterm]` section with configuration specific to `zulip-term`
@@ -216,13 +222,15 @@ A file with only the first section can be auto-generated in some cases by
216222
above). Parts of the second section can be added and adjusted in stages when
217223
you wish to customize the behavior of `zulip-term`.
218224

225+
If you’re downloading the config file from your Zulip account, you should replace the `key` field with `passcmd`, setting its value to a command that outputs the api_key (e.g., cat zulip_key). If you’re not downloading it manually, zulip-term will configure this for you automatically, though it’s recommended to update the passcmd value afterward for better security.
226+
219227
The example below, with dummy `[api]` section contents, represents a working
220228
configuration file with all the default compatible `[zterm]` values uncommented
221229
and with accompanying notes:
222230
```
223231
[api]
224232
email=example@example.com
225-
key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
233+
passcmd=cat zulip_key
226234
site=https://example.zulipchat.com
227235
228236
[zterm]
@@ -257,6 +265,7 @@ transparency=disabled
257265
# editor: nano
258266
```
259267

268+
260269
> **NOTE:** Most of these configuration settings may be specified on the
261270
command line when `zulip-term` is started; `zulip-term -h` or `zulip-term --help`
262271
will give the full list of options.

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ check_untyped_defs = false
138138
minversion = "6.0"
139139
xfail_strict = true
140140
addopts = "-rxXs --cov=zulipterminal --no-cov-on-fail"
141+
markers = [
142+
"wsl: marks tests as WSL specific",
143+
"quoted_content: marks tests dealing with quoted content rendering",
144+
]
141145
filterwarnings = [
142146
# distutils: imp module is deprecated in favor of importlib
143147
# * python3.6/3.7/3.8

tests/cli/test_run.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -575,11 +575,18 @@ def test__write_zuliprc__success(
575575
) -> None:
576576
path = os.path.join(str(tmp_path), "zuliprc")
577577

578-
error_message = _write_zuliprc(path, api_key=key, server_url=url, login_id=id)
578+
error_message = _write_zuliprc(path, server_url=url, login_id=id)
579579

580580
assert error_message == ""
581581

582-
expected_contents = f"[api]\nemail={id}\nkey={key}\nsite={url}"
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+
)
583590
with open(path) as f:
584591
assert f.read() == expected_contents
585592

@@ -595,7 +602,7 @@ def test__write_zuliprc__fail_file_exists(
595602
) -> None:
596603
path = os.path.join(str(tmp_path), "zuliprc")
597604

598-
error_message = _write_zuliprc(path, api_key=key, server_url=url, login_id=id)
605+
error_message = _write_zuliprc(path, server_url=url, login_id=id)
599606

600607
assert error_message == "zuliprc already exists at " + path
601608

tests/conftest.py

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

5455

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+
5561
# --------------- Controller Fixtures -----------------------------------------
5662

5763

tests/core/test_core.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def controller(self, mocker: MockerFixture) -> Controller:
4242
MODULE + ".urwid.MainLoop", return_value=mocker.Mock()
4343
)
4444

45+
# Mock get_api_key to return a dummy value
46+
mocker.patch.object(Controller, "get_api_key", return_value="dummy_api_key")
47+
4548
self.config_file = "path/to/zuliprc"
4649
self.theme_name = "zt_dark"
4750
self.theme = generate_theme(
@@ -76,9 +79,11 @@ def controller(self, mocker: MockerFixture) -> Controller:
7679
def test_initialize_controller(
7780
self, controller: Controller, mocker: MockerFixture
7881
) -> None:
82+
# Update the assertion to include the api_key parameter
7983
self.client.assert_called_once_with(
8084
config_file=self.config_file,
8185
client="ZulipTerminal/" + ZT_VERSION + " " + platform(),
86+
api_key="dummy_api_key", # Add this line
8287
)
8388
self.model.assert_called_once_with(controller)
8489
self.view.assert_called_once_with(controller)
@@ -483,7 +488,6 @@ def test_stream_muting_confirmation_popup(
483488
) -> None:
484489
pop_up = mocker.patch(MODULE + ".PopUpConfirmationView")
485490
text = mocker.patch(MODULE + ".urwid.Text")
486-
partial = mocker.patch(MODULE + ".partial")
487491
controller.model.muted_streams = muted_streams
488492
controller.loop = mocker.Mock()
489493

@@ -493,7 +497,7 @@ def test_stream_muting_confirmation_popup(
493497
("bold", f"Confirm {action} of stream '{stream_name}' ?"),
494498
"center",
495499
)
496-
pop_up.assert_called_once_with(controller, text(), partial())
500+
pop_up.assert_called_once()
497501

498502
@pytest.mark.parametrize(
499503
"initial_narrow, final_narrow",

tests/platform_code/test_platform_code.py

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

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

7875
@pytest.mark.parametrize(
7976
"platform, expected_return_code",
@@ -108,3 +105,14 @@ def test_normalized_file_path(
108105
) -> None:
109106
mocker.patch(MODULE + ".PLATFORM", platform)
110107
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)