-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: unit tests around protocol usage #48
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import logging | ||
|
||
from .protocol import Protocol | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from unittest.mock import Mock | ||
|
||
from slack_cli_hooks.protocol.protocol import Protocol | ||
|
||
|
||
def debug(self, msg: str, *args, **kwargs): | ||
"""This is a mock""" | ||
pass | ||
|
||
|
||
def info(self, msg: str, *args, **kwargs): | ||
"""This is a mock""" | ||
pass | ||
|
||
|
||
def warning(self, msg: str, *args, **kwargs): | ||
"""This is a mock""" | ||
pass | ||
|
||
|
||
def error(self, msg: str, *args, **kwargs): | ||
"""This is a mock""" | ||
pass | ||
|
||
|
||
def respond(self, data: str): | ||
"""This is a mock""" | ||
pass | ||
|
||
|
||
class MockProtocol(Protocol): | ||
name: str = "MockProtocol" | ||
|
||
debug = Mock(spec=debug, return_value=None) | ||
info = Mock(spec=info, return_value=None) | ||
warning = Mock(spec=warning, return_value=None) | ||
error = Mock(spec=error, return_value=None) | ||
respond = Mock(spec=respond, return_value=None) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import json | ||
import runpy | ||
import sys | ||
from unittest.mock import patch | ||
|
||
from slack_cli_hooks.hooks import get_hooks, get_manifest, start | ||
|
||
|
||
class TestGetHooks: | ||
|
||
def setup_method(self): | ||
cli_args = [get_hooks.__name__, "--protocol", "message-boundaries", "--boundary", ""] | ||
self.argv_mock = patch.object(sys, "argv", cli_args) | ||
self.argv_mock.start() | ||
|
||
def teardown_method(self): | ||
self.argv_mock.stop() | ||
|
||
def test_get_manifest(self, capsys): | ||
runpy.run_module(get_hooks.__name__, run_name="__main__") | ||
runpy.run_module(get_hooks.__name__, run_name="__main__", alter_sys=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this change need to be applied to other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 💯 this is a remnant of my experimental work |
||
|
||
out, err = capsys.readouterr() | ||
json_response = json.loads(out) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import re | ||
|
||
from slack_cli_hooks.hooks.get_hooks import hooks_payload | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm for this argument being explicit instead of falling back to the same default, but I'm wondering if we'd also want to remove that defaulting value with this change? That might be a breaking change though, so feel free to ignore - this adds a bunch of clarity as is!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this 💯 it isn't a breaking change since the
build_protocol
util is not exposed publicly