|
6 | 6 |
|
7 | 7 | import pytest
|
8 | 8 | from pytest import param as case
|
| 9 | +from pytest_mock import MockerFixture |
9 | 10 | from zulip import Client, ZulipError
|
10 | 11 |
|
11 | 12 | from zulipterminal.config.symbols import STREAM_TOPIC_SEPARATOR
|
@@ -564,25 +565,73 @@ def test_topics_in_stream(self, mocker, model, topics_index, fetched, stream_id=
|
564 | 565 | assert model.index["topics"][stream_id] is not return_value
|
565 | 566 |
|
566 | 567 | @pytest.mark.parametrize(
|
567 |
| - "email_address_stream_dict, expected_return_value", |
| 568 | + "response, expected_return_value", |
568 | 569 | [
|
569 |
| - |
570 |
| - ({}, None), |
| 570 | + ( |
| 571 | + {"result": "success", "msg": "", "email": "[email protected]"}, |
| 572 | + |
| 573 | + ), |
| 574 | + ( |
| 575 | + {"result": "error", "msg": "Invalid stream ID", "code": "BAD_REQUEST"}, |
| 576 | + None, |
| 577 | + ), |
| 578 | + ], |
| 579 | + ids=["valid_email_returned", "no_email_returned"], |
| 580 | + ) |
| 581 | + def test__fetch_stream_email_from_endpoint( |
| 582 | + self, |
| 583 | + mocker: MockerFixture, |
| 584 | + model: Any, |
| 585 | + response: Dict[str, str], |
| 586 | + expected_return_value: Optional[str], |
| 587 | + stream_id: int = 1, |
| 588 | + ) -> None: |
| 589 | + self.client.call_endpoint = mocker.Mock(return_value=response) |
| 590 | + |
| 591 | + result = model._fetch_stream_email_from_endpoint(stream_id) |
| 592 | + |
| 593 | + self.client.call_endpoint.assert_called_once_with( |
| 594 | + f"/streams/{stream_id}/email_address", method="GET" |
| 595 | + ) |
| 596 | + assert result == expected_return_value |
| 597 | + |
| 598 | + @pytest.mark.parametrize( |
| 599 | + "email_address_stream_dict, email_fetch_response, " |
| 600 | + "expected_fetched, expected_return_value", |
| 601 | + [ |
| 602 | + ( |
| 603 | + {"email_address": "[email protected]"}, |
| 604 | + None, |
| 605 | + False, |
| 606 | + |
| 607 | + ), |
| 608 | + |
| 609 | + ({}, None, True, None), |
571 | 610 | ],
|
572 | 611 | ids=[
|
573 | 612 | "email_present_in_dict:ZFL<226",
|
574 |
| - "email_absent_from_dict:ZFL>=226", |
| 613 | + "email_absent_from_dict_and_fetched_ok:ZFL>=226", |
| 614 | + "email_absent_from_dict_and_fetch_failed:ZFL>=226", |
575 | 615 | ],
|
576 | 616 | )
|
577 | 617 | def test_get_stream_email_address(
|
578 | 618 | self,
|
| 619 | + mocker: MockerFixture, |
579 | 620 | model: Any,
|
580 | 621 | email_address_stream_dict: Dict[str, str],
|
| 622 | + email_fetch_response: Optional[str], |
| 623 | + expected_fetched: bool, |
581 | 624 | expected_return_value: Optional[str],
|
582 | 625 | stream_id: int = 1,
|
583 | 626 | ) -> None:
|
584 | 627 | model.stream_dict[stream_id] = email_address_stream_dict
|
| 628 | + model._fetch_stream_email_from_endpoint = mocker.Mock( |
| 629 | + return_value=email_fetch_response |
| 630 | + ) |
| 631 | + |
585 | 632 | result = model.get_stream_email_address(stream_id)
|
| 633 | + |
| 634 | + assert model._fetch_stream_email_from_endpoint.called == expected_fetched |
586 | 635 | assert result == expected_return_value
|
587 | 636 |
|
588 | 637 | # pre server v3 provide user_id or id as a property within user key
|
|
0 commit comments