Skip to content

Commit 5d9ca11

Browse files
authored
Merge pull request #490 from aio-libs/fix/updated-new-trafaret
Fix/updated new trafaret
2 parents 2417c8b + 743dfe6 commit 5d9ca11

File tree

7 files changed

+16
-16
lines changed

7 files changed

+16
-16
lines changed

aiohttp_admin/backends/mongo_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def op(filter, field, operation, value):
3535
# TODO: fix comparators, keys should be something better
3636
comparator_map = {
3737
t.String: ('eq', 'ne', 'like', 'in'),
38-
t.Int: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'),
39-
t.Float: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
38+
t.ToInt: ('eq', 'ne', 'lt', 'le', 'gt', 'ge', 'in'),
39+
t.ToFloat: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
4040
# t.Date: ('eq', 'ne', 'lt', 'le', 'gt', 'ge'),
4141
}
4242

aiohttp_admin/backends/sa_utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def build_trafaret(sa_type, **kwargs):
2929
trafaret = t.String(max_length=sa_type.length, **kwargs)
3030

3131
elif isinstance(sa_type, sa.sql.sqltypes.Integer):
32-
trafaret = t.Int(**kwargs)
32+
trafaret = t.ToInt(**kwargs)
3333

3434
elif isinstance(sa_type, sa.sql.sqltypes.Float):
35-
trafaret = t.Float(**kwargs)
35+
trafaret = t.ToFloat(**kwargs)
3636

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

4343
elif isinstance(sa_type, sa.sql.sqltypes.Boolean):
44-
trafaret = t.StrBool(**kwargs)
44+
trafaret = t.ToBool(**kwargs)
4545

4646
# Add PG related JSON and ARRAY
4747
elif isinstance(sa_type, postgresql.JSON):

aiohttp_admin/layout_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
def build_field(key, value, relations=None):
1010
extra = None
1111
name = key
12-
if isinstance(value, t.Int):
12+
if isinstance(value, t.ToInt):
1313
v = "number"
1414
elif isinstance(value, (t.String, t.URL)):
1515
v = "string"
1616
elif isinstance(value, t.Email):
1717
v = "email"
18-
elif isinstance(value, t.Float):
18+
elif isinstance(value, t.ToFloat):
1919
v = "float"
2020
elif isinstance(value, t.Enum):
2121
v = "choice"

aiohttp_admin/utils.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def json_datetime_serial(obj):
4747
OptKey = partial(t.Key, optional=True)
4848

4949

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

6666

6767
ListQuery = t.Dict({
68-
OptKey('_page', default=1): t.Int[1:],
69-
OptKey('_perPage', default=30): t.Int[1:],
68+
OptKey('_page', default=1): t.ToInt[1:],
69+
OptKey('_perPage', default=30): t.ToInt[1:],
7070
OptKey('_sortField'): t.String,
7171
OptKey('_sortDir', default=DESC): t.Enum(DESC, ASC),
7272

requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ pytest-sugar==0.9.2
1414
pytest==5.2.2
1515
python-dateutil==2.8.0
1616
sqlalchemy==1.3.10
17-
trafaret==1.2.0
17+
trafaret==2.0.0
1818
pymysql==0.9.3
1919
-r requirements-doc.txt

tests/db_fixtures.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,13 @@ def document_schema():
154154
t.Key('title'): t.String(max_length=200),
155155
t.Key('category'): t.String(max_length=200),
156156
t.Key('body'): t.String,
157-
t.Key('views'): t.Int,
158-
t.Key('average_note'): t.Float,
157+
t.Key('views'): t.ToInt,
158+
t.Key('average_note'): t.ToFloat,
159159
# t.Key('pictures'): t.Dict({}).allow_extra('*'),
160160
t.Key('published_at'): DateTime,
161161
# t.Key('tags'): t.List(t.Int),
162162
t.Key('status'): t.Enum(*choices),
163-
t.Key('visible'): t.StrBool,
163+
t.Key('visible'): t.ToBool,
164164
})
165165
return schema
166166

tests/test_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def test_validate_payload_not_valid_schema():
131131

132132

133133
def test_as_dict():
134-
exc = t.DataError()
134+
exc = t.DataError('err')
135135
resp = as_dict(exc)
136136
assert isinstance(resp, dict)
137137

138-
exc = t.DataError()
138+
exc = t.DataError('err')
139139
assert isinstance(exc.as_dict("boom"), str)
140140

141141
resp = as_dict(exc, 'boom')

0 commit comments

Comments
 (0)