-
-
Notifications
You must be signed in to change notification settings - Fork 377
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d482e0
commit 076da5f
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import unittest | ||
import re | ||
import responses | ||
from zulip import Client | ||
|
||
from unittest import TestCase | ||
|
||
class TestClient(Client): | ||
def __init__(self, config_file: str) -> None: | ||
super().__init__(config_file=config_file) | ||
self.responses = responses.RequestsMock() | ||
self.responses.start() | ||
self.add_responses() | ||
|
||
def add_responses(self) -> None: | ||
# For call_on_each_event | ||
self.responses.add( | ||
responses.POST, | ||
url="{}v1/register".format(self.base_url), | ||
json={'queue_id': 10, 'last_event_id': -1, 'msg': '', 'result': 'success'}, | ||
status=200 | ||
) | ||
self.responses.add( | ||
responses.GET, | ||
url="{}v1/events".format(self.base_url), | ||
json={'result': 'success', 'msg': '', 'events': [{'id': 123}]}, | ||
status=200 | ||
) | ||
# For add_reaction | ||
self.responses.add( | ||
responses.POST, | ||
url=re.compile("{}v1/messages/([0-9]*)/reactions".format(self.base_url)), | ||
json={'result': 'success', 'msg': ''}, | ||
status=200 | ||
) | ||
|
||
class TerminationException(Exception): | ||
pass | ||
|
||
class TestAPI(TestCase): | ||
def __init__(self, methodName: str) -> None: | ||
super().__init__(methodName=methodName) | ||
self.client = TestClient(config_file="zulip/tests/test_zuliprc") | ||
|
||
def test_add_reaction(self) -> None: | ||
request = { | ||
"message_id": 59, | ||
"emoji_name": "octopus", | ||
} | ||
result = self.client.add_reaction(request) | ||
self.assertEqual(result, {'result': 'success', 'msg': ''}) | ||
|
||
def test_call_on_each_event(self) -> None: | ||
def terminate() -> None: | ||
raise TerminationException() | ||
try: | ||
self.client.call_on_each_event( | ||
lambda x: terminate(), | ||
['message'], | ||
) | ||
except TerminationException: | ||
pass | ||
try: | ||
self.client.call_on_each_event( | ||
lambda x: terminate(), | ||
) | ||
except TerminationException: | ||
pass | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[api] | ||
[email protected] | ||
key=K1PZuAp18Cn9RFjTsf5O1HeRW6TVpyhF | ||
site=http://localhost:9991 |