Skip to content

Commit

Permalink
Test for aggregate_rows() & get rid of limit(1) in get() (#76)
Browse files Browse the repository at this point in the history
Test for aggregate_rows() & get rid of limit(1) in get()
  • Loading branch information
CyberROFL authored and rudyryk committed Nov 15, 2017
1 parent 48942db commit 3301e5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions peewee_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async def my_async_func():
query = query.where(*conditions)

try:
result = yield from self.execute(query.limit(1))
result = yield from self.execute(query)
return list(result)[0]
except IndexError:
raise model.DoesNotExist
Expand Down Expand Up @@ -487,7 +487,7 @@ def get_object(source, *args):
model = source

# Return first object from query
for obj in (yield from select(query.where(*args).limit(1))):
for obj in (yield from select(query.where(*args))):
return obj

# No objects found
Expand Down
26 changes: 26 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,32 @@ def test(objects):

self.run_with_managers(test)

def test_aggregate_rows(self):
@asyncio.coroutine
def test(objects):
alpha = yield from objects.create(TestModelAlpha,
text='Alpha')

beta_1 = yield from objects.create(TestModelBeta,
alpha=alpha,
text='Beta 1')
beta_2 = yield from objects.create(TestModelBeta,
alpha=alpha,
text='Beta 2')

result = yield from objects.get((
TestModelAlpha
.select(TestModelAlpha, TestModelBeta)
.join(TestModelBeta)
.order_by(TestModelAlpha.text, TestModelBeta.text)
.aggregate_rows()))

self.assertEqual(result, alpha)

self.assertEqual(result.betas, [beta_1, beta_2])

self.run_with_managers(test)


#####################
# Python 3.5+ tests #
Expand Down

0 comments on commit 3301e5e

Please sign in to comment.