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 #132 from lendingblock/master
Browse files Browse the repository at this point in the history
Release v0.9.2
  • Loading branch information
markharley authored Oct 10, 2018
2 parents 194132a + 0ae6ce7 commit b4ad110
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion openapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Minimal OpenAPI asynchronous server application
"""

__version__ = '0.9.0'
__version__ = '0.9.2'
3 changes: 2 additions & 1 deletion openapi/db/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ..db.dbmodel import CrudDB
from ..spec.path import ApiPath

unique_regex = re.compile(r'Key \((?P<column>\w+)\)=\((?P<value>.+)\)')
unique_regex = re.compile(r'Key \((?P<column>(\w+,? ?)+)\)=\((?P<value>.+)\)')


class SqlApiPath(ApiPath):
Expand Down Expand Up @@ -142,6 +142,7 @@ async def delete_one(
consumer=self)
if not values:
raise web.HTTPNotFound()
return values

async def delete_list(
self, *, filters=None, query=None, table=None, conn=None):
Expand Down
7 changes: 7 additions & 0 deletions tests/example/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,11 @@ def meta(meta=None):
nullable=False)
)

sa.Table(
'multi_key_unique', meta,
sa.Column('x', sa.Integer, nullable=False),
sa.Column('y', sa.Integer, nullable=False),
sa.UniqueConstraint('x', 'y')
)

return meta
24 changes: 24 additions & 0 deletions tests/example/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .models import (
Task, TaskAdd, TaskQuery, TaskPathSchema, TaskUpdate, TaskPathSchema2,
TaskOrderableQuery,
MultiKey,
)


Expand Down Expand Up @@ -424,3 +425,26 @@ class NoTagDescriptionPath(SqlApiPath):
- Random
"""
pass


@routes.view('/multikey')
class MultiKeyPath(SqlApiPath):
"""
---
summary: Create rows in multikey constraint table
tags:
- MultiKey
"""
table = 'multi_key_unique'

@op(response_schema=MultiKey, body_schema=MultiKey)
async def post(self):
"""
---
summary: Create row in multi-column constrained table
responses:
201:
description: New row
"""
data = await self.create_one()
return self.json_response(data, status=201)
6 changes: 6 additions & 0 deletions tests/example/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ class TaskPathSchema:
@dataclass
class TaskPathSchema2:
task_id: str = uuid_field(required=True, description='Task ID')


@dataclass
class MultiKey:
x: int
y: int
24 changes: 21 additions & 3 deletions tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ async def test_spec_root(cli):
spec = await jsonBody(response)
assert 'paths' in spec
assert 'tags' in spec
assert len(spec['tags']) == 3
assert spec['tags'][1]['name'] == 'Task'
assert spec['tags'][1]['description'] == 'Simple description'
assert len(spec['tags']) == 4
assert spec['tags'][2]['name'] == 'Task'
assert spec['tags'][2]['description'] == 'Simple description'


async def test_transaction_create(cli):
Expand Down Expand Up @@ -387,3 +387,21 @@ async def test_decimal_zero_returned(cli):
get_body = await jsonBody(get_resp, status=200)

assert get_body['story_points'] == Decimal(0)


async def test_multicolumn_unique_constraint(cli):
row = {
'x': 1,
'y': 2
}
resp = await cli.post(
'/multikey',
json=row
)
await jsonBody(resp, status=201)

resp = await cli.post(
'/multikey',
json=row
)
await jsonBody(resp, status=422)

0 comments on commit b4ad110

Please sign in to comment.