-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new feature to allow regex in filtrate decorator.
- Loading branch information
Showing
9 changed files
with
149 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# https://editorconfig.org/ | ||
|
||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
end_of_line = lf | ||
charset = utf-8 | ||
|
||
# Docstrings and comments use max_line_length = 79 | ||
[*.py] | ||
max_line_length = 119 | ||
|
||
# Use 2 spaces for the HTML files | ||
[*.html] | ||
indent_size = 2 | ||
|
||
# The JSON files contain newlines inconsistently | ||
[*.json] | ||
indent_size = 2 | ||
insert_final_newline = ignore | ||
|
||
[**/admin/js/vendor/**] | ||
indent_style = ignore | ||
indent_size = ignore | ||
|
||
# Minified JavaScript files shouldn't be changed | ||
[**.min.js] | ||
indent_style = ignore | ||
insert_final_newline = ignore | ||
|
||
# Makefiles always use tabs for indentation | ||
[Makefile] | ||
indent_style = tab | ||
|
||
# Batch files use tabs for indentation | ||
[*.bat] | ||
indent_style = tab | ||
|
||
[docs/**.txt] | ||
max_line_length = 79 |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ twine = "*" | |
travis = "*" | ||
flake8 = "*" | ||
black = "*" | ||
pytest = "*" | ||
|
||
[packages] | ||
greenswitch = "*" | ||
|
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
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,3 @@ | ||
[pytest] | ||
log_cli=True | ||
console_output_style = count |
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,86 @@ | ||
from jaspion.utils import filtrate | ||
|
||
import pytest | ||
|
||
|
||
class Callback: | ||
""" | ||
Class used to represent a callback. | ||
""" | ||
def __init__(self): | ||
self.control = False | ||
|
||
def __call__(self, *args, **kwargs): | ||
self.control = True | ||
|
||
|
||
def test_filtrate_is_a_callable(): | ||
"""Verify if 'filtrate' is a callable.""" | ||
assert callable(filtrate) | ||
|
||
|
||
def test_filtrate_require_a_single_argument(): | ||
"""Verify if 'filtrate' is a callable.""" | ||
msg = "filtrate() missing 1 required positional argument: 'key'" | ||
with pytest.raises(TypeError) as exc: | ||
filtrate() # pylint: disable=no-value-for-parameter | ||
assert msg in str(exc) | ||
|
||
|
||
def test_filtrate_return_a_callable(): | ||
"""Ensures that the filtrate returns a callable when invoked correctly.""" | ||
result = filtrate('key') | ||
assert callable(result) | ||
|
||
|
||
tests = [ | ||
{'decorator': ['key'], 'response': True, 'event': {'key': 'value'}}, | ||
{ | ||
'decorator': ['key'], | ||
'response': False, | ||
'event': { | ||
'invalid_key': 'value' | ||
} | ||
}, | ||
{ | ||
'decorator': ['key', 'value'], | ||
'response': True, | ||
'event': { | ||
'key': 'value' | ||
} | ||
}, | ||
{ | ||
'decorator': ['key', 'value'], | ||
'response': False, | ||
'event': { | ||
'key': 'another_value' | ||
} | ||
}, | ||
{ | ||
'decorator': ['key', '^[a-z]{5}$', True], | ||
'response': True, | ||
'event': { | ||
'key': 'value' | ||
} | ||
}, | ||
{ | ||
'decorator': ['key', '^[a-z]{3}$', True], | ||
'response': False, | ||
'event': { | ||
'key': 'value' | ||
} | ||
} | ||
] | ||
|
||
|
||
@pytest.mark.parametrize('content', tests) | ||
def test_decorator_behavior(content): | ||
"""Validates decorator behavior.""" | ||
handler = Callback() | ||
decorator = filtrate(*content['decorator']) | ||
new_handler = decorator(handler) | ||
event = content['event'] | ||
|
||
new_handler(event) | ||
|
||
assert content['response'] == handler.control |