Skip to content

Commit 8830873

Browse files
authored
Merge pull request #267 from thenx/master
Fix #260 - SimpleType validation converts values
2 parents 91a4338 + 0ded128 commit 8830873

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

aiohttp_admin/utils.py

Lines changed: 1 addition & 1 deletion
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.Int | t.Bool | t.String | t.Float
50+
SimpleType = t.IntRaw | t.Bool | t.String | t.FloatRaw
5151
Filter = t.Dict({
5252
OptKey('in'): t.List(SimpleType),
5353
OptKey('gt'): SimpleType,

tests/test_utils.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from aiohttp_admin.exceptions import JsonValidaitonError
88
from aiohttp_admin.utils import (validate_query_structure, jsonify,
9-
validate_payload, as_dict)
9+
validate_payload, as_dict, SimpleType)
1010

1111

1212
def test_validate_query_empty_defaults():
@@ -33,6 +33,32 @@ def test_validate_query_all_possible_params():
3333
assert q == expected
3434

3535

36+
def test_simple_type():
37+
assert 42 == SimpleType(42)
38+
assert 13.37 == SimpleType(13.37)
39+
assert True is SimpleType(True)
40+
assert 'string' == SimpleType('string')
41+
assert '42' == SimpleType('42')
42+
assert '13.37' == SimpleType('13.37')
43+
44+
45+
def test_validate_query_numeric_string():
46+
filters = {
47+
'views': "20"
48+
}
49+
50+
query = {'_page': 1,
51+
'_perPage': 30,
52+
'_sortField': 'id',
53+
'_sortDir': 'DESC',
54+
'_filters': json.dumps(filters)}
55+
q = validate_query_structure(query)
56+
57+
expected = query.copy()
58+
expected['_filters'] = filters
59+
assert q == expected
60+
61+
3662
def test_validate_query_filters_is_not_json():
3763
query = {'_filters': 'foo'}
3864

0 commit comments

Comments
 (0)