Skip to content

Commit

Permalink
Merge 10379b0 into 15f0ca9
Browse files Browse the repository at this point in the history
  • Loading branch information
lafrech committed Dec 4, 2019
2 parents 15f0ca9 + 10379b0 commit 05aa954
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
9 changes: 9 additions & 0 deletions tests/frameworks/test_motor_asyncio.py
Expand Up @@ -229,6 +229,12 @@ def callback(result, error):
cursor2_student = cursor2.next_object()
assert cursor_student == cursor2_student

# Filter + projection
cursor = Student.find({'name': 'student-0'}, ['name'])
students = list(await cursor.to_list(length=100))
assert len(students) == 1
assert students[0].name == 'student-0'

loop.run_until_complete(do_test())

def test_classroom(self, loop, classroom_model):
Expand Down Expand Up @@ -763,6 +769,9 @@ class InheritanceSearchChild2(InheritanceSearchParent):
res = await InheritanceSearchChild1.find_one(isc.id)
assert res == isc

res = await InheritanceSearchChild1.find_one(isc.id, ['c1f'])
assert res.c1f == 2

loop.run_until_complete(do_test())

def test_search(self, loop, instance):
Expand Down
9 changes: 9 additions & 0 deletions tests/frameworks/test_pymongo.py
Expand Up @@ -149,6 +149,12 @@ def test_cursor(self, classroom_model):
names = (elem.name for elem in cursor[2:5])
assert sorted(names) == ['student-%s' % i for i in range(2, 5)]

# Filter + projection
cursor = Student.find({'name': 'student-0'}, ['name'])
students = list(cursor)
assert len(students) == 1
assert students[0].name == 'student-0'

def test_classroom(self, classroom_model):
student = classroom_model.Student(name='Marty McFly', birthday=datetime(1968, 6, 9))
student.commit()
Expand Down Expand Up @@ -598,6 +604,9 @@ class InheritanceSearchChild2(InheritanceSearchParent):
res = InheritanceSearchChild1.find_one(isc.id)
assert res == isc

res = InheritanceSearchChild1.find_one(isc.id, ['c1f'])
assert res.c1f == 2

def test_search(self, instance):

@instance.register
Expand Down
12 changes: 12 additions & 0 deletions tests/frameworks/test_txmongo.py
Expand Up @@ -168,6 +168,11 @@ def test_find_no_cursor(self, classroom_model):
assert isinstance(elem, Student)
names.append(elem.name)
assert sorted(names) == ['student-%s' % i for i in range(6, 10)]
# Filter + projection
results = yield Student.find({'name': 'student-0'}, ['name'])
assert isinstance(results, list)
assert len(results) == 1
assert results[0].name == 'student-0'

@pytest_inlineCallbacks
def test_find_with_cursor(self, classroom_model):
Expand All @@ -184,7 +189,11 @@ def test_find_with_cursor(self, classroom_model):
for elem in batch1:
assert isinstance(elem, Student)
names.append(elem.name)
# Filter + projection
assert sorted(names) == ['student-%s' % i for i in range(6, 10)]
batch1, cursor1 = yield Student.find({'name': 'student-0'}, ['name'], cursor=True)
assert len(batch1) == 1
assert batch1[0].name == 'student-0'

@pytest_inlineCallbacks
def test_classroom(self, classroom_model):
Expand Down Expand Up @@ -699,6 +708,9 @@ class InheritanceSearchChild2(InheritanceSearchParent):
res = yield InheritanceSearchChild1.find_one(isc.id)
assert res == isc

res = yield InheritanceSearchChild1.find_one(isc.id, ['c1f'])
assert res.c1f == 2

@pytest_inlineCallbacks
def test_search(self, instance):

Expand Down
4 changes: 2 additions & 2 deletions umongo/frameworks/motor_asyncio.py
Expand Up @@ -242,7 +242,7 @@ async def find_one(cls, filter=None, *args, **kwargs):
Find a single document in database.
"""
filter = cook_find_filter(cls, filter)
ret = await cls.collection.find_one(*args, filter=filter, **kwargs)
ret = await cls.collection.find_one(filter, *args, **kwargs)
if ret is not None:
ret = cls.build_from_mongo(ret, use_cls=True)
return ret
Expand All @@ -255,7 +255,7 @@ def find(cls, filter=None, *args, **kwargs):
Returns a cursor that provide Documents.
"""
filter = cook_find_filter(cls, filter)
return WrappedCursor(cls, cls.collection.find(*args, filter=filter, **kwargs))
return WrappedCursor(cls, cls.collection.find(filter, *args, **kwargs))

@classmethod
async def count_documents(cls, filter=None, *, with_limit_and_skip=False, **kwargs):
Expand Down
4 changes: 2 additions & 2 deletions umongo/frameworks/pymongo.py
Expand Up @@ -190,7 +190,7 @@ def find_one(cls, filter=None, *args, **kwargs):
Find a single document in database.
"""
filter = cook_find_filter(cls, filter)
ret = cls.collection.find_one(*args, filter=filter, **kwargs)
ret = cls.collection.find_one(filter, *args, **kwargs)
if ret is not None:
ret = cls.build_from_mongo(ret, use_cls=True)
return ret
Expand All @@ -203,7 +203,7 @@ def find(cls, filter=None, *args, **kwargs):
Returns a cursor that provide Documents.
"""
filter = cook_find_filter(cls, filter)
raw_cursor = cls.collection.find(*args, filter=filter, **kwargs)
raw_cursor = cls.collection.find(filter, *args, **kwargs)
return cls.cursor_cls(cls, raw_cursor)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions umongo/frameworks/txmongo.py
Expand Up @@ -154,7 +154,7 @@ def find_one(cls, spec=None, *args, **kwargs):
"""
# In txmongo, `spec` is for filtering and `filter` is for sorting
spec = cook_find_filter(cls, spec)
ret = yield cls.collection.find_one(*args, spec=spec, **kwargs)
ret = yield cls.collection.find_one(spec, *args, **kwargs)
if ret is not None:
ret = cls.build_from_mongo(ret, use_cls=True)
return ret
Expand All @@ -169,7 +169,7 @@ def find(cls, spec=None, *args, **kwargs):
"""
# In txmongo, `spec` is for filtering and `filter` is for sorting
spec = cook_find_filter(cls, spec)
raw_cursor_or_list = yield cls.collection.find(*args, spec=spec, **kwargs)
raw_cursor_or_list = yield cls.collection.find(spec, *args, **kwargs)
if isinstance(raw_cursor_or_list, tuple):

def wrap_raw_results(result):
Expand Down

0 comments on commit 05aa954

Please sign in to comment.