Skip to content

Commit

Permalink
Rewrite master with tesplugin and link converter
Browse files Browse the repository at this point in the history
  • Loading branch information
chillipeper committed May 4, 2019
1 parent 232b77d commit c73617d
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 5 deletions.
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@


tests_require = [
'mock',
'pytest',
'pytest-cov',
'pytest-runner',
'mock'
'pytest-mock',
'freezegun'
]

setup_requires = []
Expand Down
11 changes: 10 additions & 1 deletion will/backends/io_adapters/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ class SlackMarkdownConverter(MarkdownConverter):
def convert_strong(self, el, text):
return '*%s*' % text if text else ''

def convert_a(self, el, text):
href = el.get('href')
title = el.get('title')
if self.options['autolinks'] and text == href and not title:
# Shortcut syntax
return '<%s>' % href
title_part = ' "%s"' % title.replace('"', r'\"') if title else ''
return '<%s%s|%s>' % (href, title_part, text or '') if href else text or ''


class SlackBackend(IOBackend, SleepMixin, StorageMixin):
friendly_name = "Slack"
Expand Down Expand Up @@ -347,7 +356,7 @@ def send_message(self, event):
})
if hasattr(event, "kwargs") and "html" in event.kwargs and event.kwargs["html"]:
data.update({
"parse": "full",
"parse": "none",
})

headers = {'Accept': 'text/plain'}
Expand Down
5 changes: 5 additions & 0 deletions will/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ def schedule_say(self, content, when, message=None, room=None, channel=None, ser
elif room:
channel = room

# This does not look like testable code, or something that will ever
# happen. If we have a required "content" positional argument, if
# a "content" key commes in kwargs, python will fail with a:
# TypeError: schedule_say() got multiple values for keyword argument
# 'content'
if "content" in kwargs:
if content:
del kwargs["content"]
Expand Down
2 changes: 1 addition & 1 deletion will/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ regex==2017.9.23
redis==2.10.6
requests==2.20.0
six==1.10.0
urllib3[secure]
urllib3==1.24.2
websocket-client==0.44.0
2 changes: 2 additions & 0 deletions will/requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ yappi
tox
pytest
pytest-cov
pytest-mock
freezegun
50 changes: 48 additions & 2 deletions will/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
import datetime

import pytest

from will.abstractions import Message, Person
from will.abstractions import Event, Message, Person

# Any fixtures defined in this file will be automatically imported into
# discovered tests.
# https://docs.pytest.org/en/latest/fixture.html#conftest-py-sharing-fixture-functions


IO_BACKENDS = [
"will.backends.io_adapters.slack",
"will.backends.io_adapters.rocketchat",
"will.backends.io_adapters.shell"
]

ANALYZE_BACKENDS = [
"will.backends.analysis.nothing",
"will.backends.analysis.history"
]


@pytest.fixture()
def all_io_backends():
return IO_BACKENDS


@pytest.fixture(params=IO_BACKENDS)
def io_backend(request):
"""Parametrized fixture of available io backends"""

return request.param


@pytest.fixture(params=ANALYZE_BACKENDS)
def analysis(request):
"""Parametrized fixture of available analysis backends"""

return request.param


@pytest.fixture()
def person():
"""Mimic person abstraction"""
def _person(fields):
required_fields = {
"id": "TDB",
"id": "TBD",
"mention_handle": "TBD",
"source": "TBD",
"handle": "TBD",
Expand Down Expand Up @@ -45,4 +78,17 @@ def _message(fields):
required_fields.update(fields)

return Message(**required_fields)

return _message


@pytest.fixture()
def event():
"""Mimic event abstraction"""
def _event(fields):
required_fields = {"type": "TBD", "version": 1}
required_fields.update(fields)

return Event(**required_fields)

return _event
4 changes: 4 additions & 0 deletions will/tests/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""Contain constants to be used for tests"""

# Used to freeze_time
WILLS_BIRTHDAY = "2013-12-04 01:11:00"
Loading

0 comments on commit c73617d

Please sign in to comment.