Skip to content

Feature#36 #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Core
aiopg==0.10.0
peewee==2.8.3
peewee-async==0.5.5
psycopg2==2.6.2
aiopg==0.15.0
peewee==3.7.0
peewee-async==0.6.0a
psycopg2==2.7.5
tornado==4.4.2
jsonschema==2.5.1
msgpack-python==0.4.8
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ def get_long_description(f):


install_requires = [
'peewee>=2.8.3',
'peewee-async>=0.5.5',
'aiopg==0.15.0'
'peewee==3.7.0',
'peewee-async>=0.6.0a',
'tornado>=4.4.2',
'jsonschema>=2.5.1',
'msgpack-python>=0.4.8',
Expand Down
13 changes: 7 additions & 6 deletions tcrudge/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,11 @@ def qs_order_by(cls, qs, value, process_value=True):
if ordr[0] == '-':
# DESC order
fld = getattr(cls.model_cls, ordr[1:])
qs = qs.order_by(fld.desc(), extend=True)
qs = qs.order_by(fld.desc())
else:
# ASC order
fld = getattr(cls.model_cls, ordr)
qs = qs.order_by(fld, extend=True)
qs = qs.order_by(fld)
return qs

def get_queryset(self, paginate=True):
Expand Down Expand Up @@ -618,7 +618,7 @@ async def get(self):
{
'code': '',
'message': 'Bad query arguments',
'detail': str(e)
'detail': xhtml_escape(str(e))
}
]
)
Expand Down Expand Up @@ -677,14 +677,15 @@ async def post(self):
item = await self.model_cls._create(self.application, data)
except AttributeError as e:
# We can only create item if _create() model method implemented
err = xhtml_escape(str(e))
raise HTTPError(
405,
body=self.get_response(
errors=[
{
'code': '',
'message': 'Method not allowed',
'detail': str(e)
'detail': err
}
]
)
Expand Down Expand Up @@ -794,7 +795,7 @@ async def get_item(self, item_id):
{
'code': '',
'message': 'Item not found',
'detail': str(e)
'detail': xhtml_escape(str(e))
}
]
)
Expand Down Expand Up @@ -843,7 +844,7 @@ async def put(self, item_id):
{
'code': '',
'message': 'Method not allowed',
'detail': str(e)
'detail': xhtml_escape(str(e))
}
]
)
Expand Down
2 changes: 1 addition & 1 deletion tcrudge/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def to_schema(cls, excluded=None):
if field not in excluded:
schema.add_object(
{
field: type_field.get_column_type()
field: type_field.field_type
}
)
if not type_field.null:
Expand Down
6 changes: 3 additions & 3 deletions tcrudge/utils/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

PEEWEE_TYPES = {
'SERIAL': [
'AUTO': [
{"type": "integer"},
{"type": "string", "pattern": "^[+-]?[0-9]+$"},
],
Expand All @@ -27,11 +27,11 @@
'BOOLEAN': 'boolean',
'JSONB': 'object',
'JSON': 'object',
'INTEGER': [
'INT': [
{"type": "integer"},
{"type": "string", "pattern": "^[+-]?[0-9]+$"}
],
'REAL': [
'FLOAT': [
{"type": "number"},
{"type": "string", "pattern": "^[+-]?([0-9]*[.])?[0-9]+$"}
],
Expand Down
13 changes: 5 additions & 8 deletions tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def _delete(self, app):


class ApiTestModelFK(BaseModel):
tf_foreign_key = peewee.ForeignKeyField(ApiTestModel, related_name='rel_items')
tf_foreign_key = peewee.ForeignKeyField(ApiTestModel, backref='rel_items')

class Meta:
database = db
Expand Down Expand Up @@ -89,7 +89,7 @@ class ApiListTestHandlerPrefetch(ApiListHandler):
async def serialize(self, m):
result = await super(ApiListTestHandlerPrefetch, self).serialize(m)
result['rel_items'] = []
for prefetched_item in m.rel_items_prefetch:
for prefetched_item in m.rel_items:
result['rel_items'].append(model_to_dict(prefetched_item, recurse=False))
return result

Expand Down Expand Up @@ -280,10 +280,7 @@ async def test_base_api_list_head(http_client, base_url):
('tf_boolean=0', 1),
])
async def test_base_api_list_filter(http_client, base_url, url_param, cnt, monkeypatch):
monkeypatch.setattr(ApiListTestHandler, 'get_schema_input',
{

})
monkeypatch.setattr(ApiListTestHandler, 'get_schema_input', {})
res = await http_client.fetch(base_url + '/test/api_test_model/?%s' % url_param)

assert res.code == 200
Expand Down Expand Up @@ -398,8 +395,8 @@ async def test_base_api_list_filter_bad_request1(http_client, base_url, url_para
assert data['result'] is None
assert not data['success']
assert len(data['errors']) == 1
assert '<' in data['errors'][0]['detail']
assert '>' in data['errors'][0]['detail']
assert 'lt;' in data['errors'][0]['detail']
assert 'gt;' in data['errors'][0]['detail']


@pytest.mark.gen_test
Expand Down