Skip to content

Commit

Permalink
[WIP] update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vchrombie committed Aug 10, 2020
1 parent 41d3cfc commit 5dd24c9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
32 changes: 32 additions & 0 deletions perceval/backends/core/zulip.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,38 @@ def parse_messages(self, raw_messages):

return anchor, found_newest, messages

# def fetch_items(self, category, **kwargs):
# """Fetch the messages.
#
# :param category: the category of items to fetch
# :param kwargs: backend arguments
#
# :return: a generator of items
# """
#
# anchor = 'oldest'
# fetching = True
#
# while fetching:
# raw_messages = self.client.get_messages(anchor)
#
# found_newest, messages = self.parse_messages(raw_messages)
#
# for message in messages:
# yield message
# anchor = message['id']
#
# if found_newest:
# fetching = False
#
# def parse_messages(self, raw_messages):
# result = json.loads(raw_messages)
#
# found_newest = result.get('found_newest', False)
# messages = result.get('messages', None)
#
# return found_newest, messages

@classmethod
def has_archiving(cls):
"""Returns whether it supports archiving items on the fetch process.
Expand Down
18 changes: 17 additions & 1 deletion tests/test_zulip.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
ZulipCommand)


ZULIP_CHAT_URL = 'https://example.zulipchat.com/'
ZULIP_CHAT_URL = 'https://example.zulipchat.com'
ZULIP_CHAT_API_URL = '/api/v1/messages'
ZULIP_MESSAGE_URL = ZULIP_CHAT_URL + ZULIP_CHAT_API_URL

email='[email protected]'
api_token='aaaa'
AUTH = (email, api_token)


def read_file(filename):
with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), filename), 'rb') as f:
Expand All @@ -63,6 +67,18 @@ def setup_http_server():
status=200)


class MockedZulipClient(ZulipClient):
"""Mocked Zulip client for testing"""

def __init__(self, url, stream, email, api_token, archive=None,
from_archive=False, ssl_verify=True):
super().__init__(url, stream, email, api_token,
archive=archive,
from_archive=from_archive,
ssl_verify=ssl_verify
)


class TestZulipBackend(unittest.TestCase):
"""Zulip backend tests"""

Expand Down

0 comments on commit 5dd24c9

Please sign in to comment.