Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #45 from lendingblock/master
Browse files Browse the repository at this point in the history
0.3.0
  • Loading branch information
lsbardel authored Jul 13, 2018
2 parents 14366b0 + 61b9376 commit 3ca187c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ python-dotenv
pytz
pyyaml
pyjwt
phonenumbers
email_validator
#
# required for python 3.6
dataclasses
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Minimal OpenAPI asynchronous server application
"""
__version__ = '0.2.6'
__version__ = '0.3.0'
12 changes: 7 additions & 5 deletions openapi/data/fields.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import re
from decimal import Decimal
from uuid import UUID
from datetime import datetime
from dataclasses import field, Field

from email_validator import validate_email, EmailNotValidError

from dateutil.parser import parse as parse_date

from ..utils import compact_dict

email_pattern = re.compile("^[a-zA-Z0-9-_]+@[a-zA-Z0-9]+\.[a-z]{1,3}$")


DEFAULT = 'default'
REQUIRED = 'required'
Expand Down Expand Up @@ -115,8 +114,11 @@ def field_ops(field):

def email_validator(field, value, data=None):
value = str(value)
if not email_pattern.match(value):
raise ValidationError(field.name, '%s not a valid email' % value)
try:
validate_email(value, check_deliverability=False)
except EmailNotValidError:
raise ValidationError(
field.name, '%s not a valid email' % value) from None
return value


Expand Down
6 changes: 3 additions & 3 deletions openapi/db/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def get_list(
"""Get a list of models
"""
table = table if table is not None else self.db_table
params = self.get_filters(query, query_schema=query_schema)
params = self.get_filters(query=query, query_schema=query_schema)
limit = params.pop('limit', DEF_PAGINATION_LIMIT)
offset = params.pop('offset', 0)
query = self.get_query(table.select(), params, table=table)
Expand Down Expand Up @@ -104,7 +104,7 @@ async def get_one(
"""Get a single model
"""
table = table if table is not None else self.db_table
filters = self.get_filters(query, query_schema=query_schema)
filters = self.get_filters(query=query, query_schema=query_schema)
query = self.get_query(table.select(), filters, table=table)
sql, args = compile_query(query)

Expand Down Expand Up @@ -149,7 +149,7 @@ async def delete_one(self, conn=None):
async def delete_list(self, query=None, conn=None):
"""delete multiple models
"""
filters = self.get_filters(query)
filters = self.get_filters(query=query)
delete = self.get_query(self.db_table.delete(), filters)
sql, args = compile_query(delete)

Expand Down
2 changes: 1 addition & 1 deletion openapi/spec/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def insert_data(self, data, strict=True, body_schema='body_schema'):
data.update(path)
return data

def get_filters(self, query=None, query_schema='query_schema'):
def get_filters(self, *, query=None, query_schema='query_schema'):
combined = dict(self.request.query)
combined.update(query or {})
try:
Expand Down
6 changes: 2 additions & 4 deletions tests/data/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,13 @@ def test_email_validator_valid():
field = email_field()
assert email_validator(field, '[email protected]') == '[email protected]'
assert email_validator(field, '[email protected]') == '[email protected]'
assert email_validator(field, '[email protected]') == '[email protected]'
assert email_validator(field, '[email protected]') == '[email protected]'


def test_email_validator_invalid():
field = email_field()
with pytest.raises(ValidationError):
email_validator(field, '[email protected]')
with pytest.raises(ValidationError):
email_validator(field, '#$%@email.com')
email_validator(field, 'a@email')
with pytest.raises(ValidationError):
email_validator(field, 'email.com')
with pytest.raises(ValidationError):
Expand Down

0 comments on commit 3ca187c

Please sign in to comment.