Skip to content

Commit 114ec0d

Browse files
prah23neiljp
authored andcommitted
refactor: model: Type recipients as List[str] in send_private_message.
Currently, the send_private_message() method expects a str for the recipients parameter. This commit modifies it to List[str] and also adds a check against an empty recipient list by raising a Runtime Error. Tests updated.
1 parent b9dd8dd commit 114ec0d

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

tests/model/test_model.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,13 @@ def test_react_to_message_for_not_thumbs_up(self, model):
438438
({'result': 'success'}, True),
439439
({'result': 'some_failure'}, False),
440440
])
441+
@pytest.mark.parametrize('recipients', [
442+
443+
444+
])
441445
def test_send_private_message(self, mocker, model,
442-
response, return_value,
443-
content="hi!",
444-
recipients="[email protected]"):
446+
recipients, response, return_value,
447+
content="hi!"):
445448
self.client.send_message = mocker.Mock(return_value=response)
446449

447450
result = model.send_private_message(recipients, content)
@@ -453,6 +456,12 @@ def test_send_private_message(self, mocker, model,
453456
self.display_error_if_present.assert_called_once_with(response,
454457
self.controller)
455458

459+
def test_send_private_message_with_no_recipients(self, model,
460+
content="hi!",
461+
recipients=[]):
462+
with pytest.raises(RuntimeError):
463+
model.send_private_message(recipients, content)
464+
456465
@pytest.mark.parametrize('response, return_value', [
457466
({'result': 'success'}, True),
458467
({'result': 'some_failure'}, False),

zulipterminal/model.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,19 @@ def mark_message_ids_as_read(self, id_list: List[int]) -> None:
333333
})
334334
display_error_if_present(response, self.controller)
335335

336-
def send_private_message(self, recipients: str,
336+
def send_private_message(self, recipients: List[str],
337337
content: str) -> bool:
338-
request = {
339-
'type': 'private',
340-
'to': recipients,
341-
'content': content,
342-
}
343-
response = self.client.send_message(request)
344-
display_error_if_present(response, self.controller)
345-
return response['result'] == 'success'
338+
if recipients:
339+
request = {
340+
'type': 'private',
341+
'to': recipients,
342+
'content': content,
343+
}
344+
response = self.client.send_message(request)
345+
display_error_if_present(response, self.controller)
346+
return response['result'] == 'success'
347+
else:
348+
raise RuntimeError('Empty recipients list.')
346349

347350
def send_stream_message(self, stream: str, topic: str,
348351
content: str) -> bool:

zulipterminal/ui_tools/boxes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
378378
msg_id=self.msg_edit_id,
379379
)
380380
else:
381+
recipient_emails = [email.strip() for email in
382+
self.to_write_box.edit_text.split(',')]
381383
success = self.model.send_private_message(
382-
recipients=self.to_write_box.edit_text,
384+
recipients=recipient_emails,
383385
content=self.msg_write_box.edit_text
384386
)
385387
if success:

0 commit comments

Comments
 (0)