Skip to content

Commit

Permalink
Merge pull request #490 from aio-libs/fix/updated-new-trafaret
Browse files Browse the repository at this point in the history
Fix/updated new trafaret
  • Loading branch information
Arfey authored Nov 3, 2019
2 parents 2417c8b + 743dfe6 commit 5d9ca11
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions aiohttp_admin/backends/mongo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def op(filter, field, operation, value):
# TODO: fix comparators, keys should be something better
comparator_map = {
t.String: ('eq', 'ne', 'like', 'in'),
t.Int: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'),
t.Float: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
t.ToInt: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'),
t.ToFloat: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
# t.Date: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
}

Expand Down
6 changes: 3 additions & 3 deletions aiohttp_admin/backends/sa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ def build_trafaret(sa_type, **kwargs):
trafaret = t.String(max_length=sa_type.length, **kwargs)

elif isinstance(sa_type, sa.sql.sqltypes.Integer):
trafaret = t.Int(**kwargs)
trafaret = t.ToInt(**kwargs)

elif isinstance(sa_type, sa.sql.sqltypes.Float):
trafaret = t.Float(**kwargs)
trafaret = t.ToFloat(**kwargs)

elif isinstance(sa_type, sa.sql.sqltypes.DateTime):
trafaret = DateTime(**kwargs) # RFC3339
Expand All @@ -41,7 +41,7 @@ def build_trafaret(sa_type, **kwargs):
trafaret = DateTime(**kwargs) # RFC3339

elif isinstance(sa_type, sa.sql.sqltypes.Boolean):
trafaret = t.StrBool(**kwargs)
trafaret = t.ToBool(**kwargs)

# Add PG related JSON and ARRAY
elif isinstance(sa_type, postgresql.JSON):
Expand Down
4 changes: 2 additions & 2 deletions aiohttp_admin/layout_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
def build_field(key, value, relations=None):
extra = None
name = key
if isinstance(value, t.Int):
if isinstance(value, t.ToInt):
v = "number"
elif isinstance(value, (t.String, t.URL)):
v = "string"
elif isinstance(value, t.Email):
v = "email"
elif isinstance(value, t.Float):
elif isinstance(value, t.ToFloat):
v = "float"
elif isinstance(value, t.Enum):
v = "choice"
Expand Down
6 changes: 3 additions & 3 deletions aiohttp_admin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def json_datetime_serial(obj):
OptKey = partial(t.Key, optional=True)


SimpleType = t.IntRaw | t.Bool | t.String | t.FloatRaw
SimpleType = t.Int | t.Bool | t.String | t.Float
Filter = t.Dict({
OptKey('in'): t.List(SimpleType),
OptKey('gt'): SimpleType,
Expand All @@ -65,8 +65,8 @@ def json_datetime_serial(obj):


ListQuery = t.Dict({
OptKey('_page', default=1): t.Int[1:],
OptKey('_perPage', default=30): t.Int[1:],
OptKey('_page', default=1): t.ToInt[1:],
OptKey('_perPage', default=30): t.ToInt[1:],
OptKey('_sortField'): t.String,
OptKey('_sortDir', default=DESC): t.Enum(DESC, ASC),

Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ pytest-sugar==0.9.2
pytest==5.2.2
python-dateutil==2.8.0
sqlalchemy==1.3.10
trafaret==1.2.0
trafaret==2.0.0
pymysql==0.9.3
-r requirements-doc.txt
6 changes: 3 additions & 3 deletions tests/db_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ def document_schema():
t.Key('title'): t.String(max_length=200),
t.Key('category'): t.String(max_length=200),
t.Key('body'): t.String,
t.Key('views'): t.Int,
t.Key('average_note'): t.Float,
t.Key('views'): t.ToInt,
t.Key('average_note'): t.ToFloat,
# t.Key('pictures'): t.Dict({}).allow_extra('*'),
t.Key('published_at'): DateTime,
# t.Key('tags'): t.List(t.Int),
t.Key('status'): t.Enum(*choices),
t.Key('visible'): t.StrBool,
t.Key('visible'): t.ToBool,
})
return schema

Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ def test_validate_payload_not_valid_schema():


def test_as_dict():
exc = t.DataError()
exc = t.DataError('err')
resp = as_dict(exc)
assert isinstance(resp, dict)

exc = t.DataError()
exc = t.DataError('err')
assert isinstance(exc.as_dict("boom"), str)

resp = as_dict(exc, 'boom')
Expand Down

0 comments on commit 5d9ca11

Please sign in to comment.