Skip to content

Commit

Permalink
Fix tests and dependencies (#11)
Browse files Browse the repository at this point in the history
- Improve test coverage
- Upgrade Pillow version
- Fix typos in the documentation
  • Loading branch information
codingedward authored Aug 16, 2020
1 parent cfdb5a3 commit 812da0e
Show file tree
Hide file tree
Showing 11 changed files with 308 additions and 359 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ requests = "*"
python-dateutil = "*"
pytz = "*"
flask = "*"
pillow = "*"
pillow = ">=7.1.0"
recommonmark = "*"
urllib3 = "*"
werkzeug = "*"
Expand Down
562 changes: 250 additions & 312 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
# -- Project information -----------------------------------------------------

project = 'Flask-Sieve'
copyright = '2019, Edward Njoroge'
copyright = '2020, Edward Njoroge'
author = 'Edward Njoroge'

# The short X.Y version
version = '0.0.2'
version = '1.1'
# The full version, including alpha/beta/rc tags
release = 'alpha'
release = '1.1.2'


# -- General configuration ---------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions docs/source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class RegisterRequest(FormRequest):
#### Custom Rules on `Validator` Instance

To add a custom rule handler to a `Validator` instance, you have will have to use
`register_custom_handler` method as shown below:
`register_rule_handler` method as shown below:

```python
from flask import Flask, jsonify, request
Expand All @@ -310,7 +310,7 @@ def validate_odd(value, **kwargs):
def register():
rules = {'avatar': ['image', 'dimensions:200x200']}
validator = Validator(rules=rules, request=request)
validator.register_custom_handler(
validator.register_rule_handler(
handler=validate_odd,
message='Must be odd',
params_count=0
Expand Down
3 changes: 0 additions & 3 deletions flask_sieve/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ def validate(self):
raise ValidationException(self._validator.messages())
return True

def register_rule_handler(self, handler, message, params_count=0):
pass

@staticmethod
def messages():
return {}
Expand Down
2 changes: 1 addition & 1 deletion flask_sieve/rules_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def validate_digits_between(self, value, params, **kwargs):

def validate_dimensions(self, value, params, **kwargs):
self._assert_params_size(size=1, params=params, rule='dimensions')
if not self.validate_file(value):
if not self.validate_image(value):
return False
try:
image = Image.open(value)
Expand Down
2 changes: 1 addition & 1 deletion flask_sieve/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def set_custom_messages(self, messages):

def set_custom_handlers(self, handlers):
for handler in handlers:
self.register_error_handler(**handler)
self.register_rule_handler(**handler)

def register_rule_handler(self, handler, message, params_count=0):
if not handler.__name__.startswith('validate_'):
Expand Down
51 changes: 22 additions & 29 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,51 +1,44 @@
alabaster==0.7.12
Babel==2.8.0
certifi==2019.11.28
certifi==2020.6.20
cffi==1.14.0
chardet==3.0.4
click==7.1.1
click==7.1.2
commonmark==0.9.1
configparser==4.0.2
contextlib2==0.6.0.post1
coverage==5.0.4
coveralls==1.11.1
coverage==5.2.1
coveralls==2.1.2
cryptography==2.8
docopt==0.6.2
docutils==0.16
enum34==1.1.10
Flask==1.1.1
future==0.18.2
idna==2.9
Flask==1.1.2
idna==2.10
imagesize==1.2.0
importlib-metadata==1.6.0
ipaddress==1.0.23
itsdangerous==1.1.0
Jinja2==2.11.1
Jinja2==2.11.2
MarkupSafe==1.1.1
nose==1.3.7
packaging==20.3
packaging==20.4
Pallets-Sphinx-Themes==1.2.3
pathlib2==2.3.5
Pillow==6.2.2
Pillow==7.2.0
pycparser==2.20
Pygments==2.5.2
Pygments==2.6.1
pyOpenSSL==19.1.0
pyparsing==2.4.6
pyparsing==2.4.7
python-dateutil==2.8.1
pytz==2019.3
pytz==2020.1
recommonmark==0.6.0
requests==2.23.0
scandir==1.10.0
six==1.14.0
requests==2.24.0
six==1.15.0
snowballstemmer==2.0.0
Sphinx==1.8.5
sphinxcontrib-applehelp==1.0.1
sphinxcontrib-devhelp==1.0.1
sphinxcontrib-htmlhelp==1.0.2
sphinxcontrib-qthelp==1.0.2
sphinxcontrib-serializinghtml==1.1.3
Sphinx==3.2.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sphinxcontrib-websupport==1.1.2
typing==3.7.4.1
urllib3==1.25.8
urllib3==1.25.10
Werkzeug==1.0.1
zipp==1.2.0
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name='flask-sieve',
description='A Laravel inspired requests validator for Flask',
long_description='Find the documentation at https://flask-sieve.readthedocs.io/en/latest/',
version='1.1.0',
version='1.1.2',
url='https://github.com/codingedward/flask-sieve',
license='BSD-2',
author='Edward Njoroge',
Expand Down
6 changes: 1 addition & 5 deletions tests/test_rules_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,7 @@ def test_validates_dimensions(self):
)
self.assert_fails(
rules={'field': ['dimensions:2x1']},
request={'field': self.invalid_file}
)
self.assert_fails(
rules={'field': ['dimensions:2x1']},
request={'field': 'hi'}
request={'field': 'not a file'}
)

def test_validates_distinct(self):
Expand Down
27 changes: 26 additions & 1 deletion tests/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def __init__(self):
validator.set_request(request)
self.assertTrue(validator.passes())


def test_validate_decorator(self):
class FailingRequest:
def validate(self):
Expand Down Expand Up @@ -120,6 +119,32 @@ def validate_odd(value, **kwargs):
)
self.assertTrue(self._validator.passes())

def test_translates_validations_set_through_custom_handlers(self):
def validate_odd(value, **kwargs):
return int(value) % 2
self._validator.set_custom_handlers([
{
'handler': validate_odd,
'message':'This number must be odd.',
'params_count':0
}
])
self.set_validator_params(
rules={'number': ['odd']},
request={'number': 4}
)
self.assertTrue(self._validator.fails())
self.assertDictEqual({
'number': [
'This number must be odd.'
]
}, self._validator.messages())
self.set_validator_params(
rules={'number': ['odd']},
request={'number': 3}
)
self.assertTrue(self._validator.passes())

def test_cannot_set_custom_handler_without_validate_keyword(self):
def method_odd(value, **kwargs):
return int(value) % 2
Expand Down

0 comments on commit 812da0e

Please sign in to comment.