Skip to content

Commit 1d662b9

Browse files
committed
refactor: conftest: Make display_recipient_factory a fixture.
This commit adds the pytest fixture decorator to display_recipient_ factory() function, allowing it to be reused separately throughout the codebase.
1 parent e7c785f commit 1d662b9

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

tests/conftest.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,27 @@ def zulip_emoji():
260260
return OrderedDict([("zulip", {"code": "zulip", "type": "zulip_extra_emoji"})])
261261

262262

263-
def display_recipient_factory(
264-
recipient_id: Optional[int] = None, recipient_name: str = ""
265-
):
263+
@pytest.fixture
264+
def display_recipient_factory():
266265
"""
267266
Generate display_recipient field for (stream/PM/group) messages
268267
FIXME: Refactor other tests to make this depend only on recipient_id.
269268
"""
270-
return (
271-
{
272-
"id": recipient_id,
273-
"is_mirror_dummy": False,
274-
"full_name": recipient_name,
275-
"short_name": f"{recipient_id}",
276-
"email": f"user-{recipient_id}@zulip.com",
277-
}
278-
if recipient_id
279-
else "PTEST"
280-
)
269+
270+
def _factory(recipient_id: Optional[int] = None, recipient_name: str = ""):
271+
return (
272+
{
273+
"id": recipient_id,
274+
"is_mirror_dummy": False,
275+
"full_name": recipient_name,
276+
"short_name": f"{recipient_id}",
277+
"email": f"user-{recipient_id}@zulip.com",
278+
}
279+
if recipient_id
280+
else "PTEST"
281+
)
282+
283+
return _factory
281284

282285

283286
@pytest.fixture
@@ -320,14 +323,14 @@ def _factory(
320323

321324

322325
@pytest.fixture
323-
def stream_msg_template(msg_template_factory):
326+
def stream_msg_template(display_recipient_factory, msg_template_factory):
324327
recipient = display_recipient_factory()
325328
msg_template = msg_template_factory(537286, "stream", 205, 1520918722, recipient)
326329
return msg_template
327330

328331

329332
@pytest.fixture
330-
def pm_template(msg_template_factory):
333+
def pm_template(display_recipient_factory, msg_template_factory):
331334
recipients = [
332335
display_recipient_factory(_id, name)
333336
for _id, name in {(5179, "Boo Boo"), (5140, "Foo Foo")}
@@ -337,7 +340,7 @@ def pm_template(msg_template_factory):
337340

338341

339342
@pytest.fixture
340-
def group_pm_template(msg_template_factory):
343+
def group_pm_template(display_recipient_factory, msg_template_factory):
341344
recipients = [
342345
display_recipient_factory(_id, name)
343346
for _id, name in {(5179, "Boo Boo"), (5140, "Foo Foo"), (5180, "Bar Bar")}

0 commit comments

Comments
 (0)