Skip to content

Commit 31536f5

Browse files
author
Mike Dirolf
committed
more tests and a fix
1 parent 10060b0 commit 31536f5

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

datastore_mongo_stub.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,9 @@ def _Dynamic_RunQuery(self, query, query_result):
386386

387387
app = query.app()
388388

389+
query_result.mutable_cursor().set_cursor(0)
390+
query_result.set_more_results(False)
391+
389392
if self.__require_indexes:
390393
required, kind, ancestor, props, num_eq_filters = datastore_index.CompositeIndexForQuery(query)
391394
if required:
@@ -418,8 +421,6 @@ def _Dynamic_RunQuery(self, query, query_result):
418421
# the types of the properties)...
419422
prototype = self.__db[collection].find_one()
420423
if prototype is None:
421-
query_result.mutable_cursor().set_cursor(0)
422-
query_result.set_more_results(False)
423424
return
424425
prototype = datastore.Entity._FromPb(self.__entity_for_mongo_document(prototype))
425426

@@ -446,20 +447,24 @@ def _Dynamic_RunQuery(self, query, query_result):
446447

447448
(key, value) = self.__filter_binding(prop, filter_val_list[0], op, prototype)
448449

449-
# TODO this can't be the right way to handle this case... need more tests
450450
if key in spec:
451-
query_result.mutable_cursor().set_cursor(0)
452-
query_result.set_more_results(False)
453-
return
454-
455-
spec[key] = value
451+
if not isinstance(spec[key], types.DictType) and not isinstance(value, types.DictType):
452+
if spec[key] != value:
453+
return
454+
elif not isinstance(spec[key], types.DictType):
455+
value["$in"] = [spec[key]]
456+
spec[key] = value
457+
elif not isinstance(value, types.DictType):
458+
spec[key]["$in"] = [value]
459+
else:
460+
spec[key].update(value)
461+
else:
462+
spec[key] = value
456463

457464
cursor = self.__db[collection].find(spec)
458465

459466
order = self.__translate_order_for_mongo(query.order_list(), prototype)
460467
if order is None:
461-
query_result.mutable_cursor().set_cursor(0)
462-
query_result.set_more_results(False)
463468
return
464469
if order:
465470
cursor = cursor.sort(order)
@@ -476,13 +481,13 @@ def _Dynamic_RunQuery(self, query, query_result):
476481
self.__queries[cursor_index] = cursor
477482

478483
query_result.mutable_cursor().set_cursor(cursor_index)
479-
query_result.set_more_results(True) # see if we can get away with always feigning more results
484+
query_result.set_more_results(True)
480485

481486
def _Dynamic_Next(self, next_request, query_result):
482487
cursor = next_request.cursor().cursor()
488+
query_result.set_more_results(False)
483489

484490
if cursor == 0: # we exited early from the query w/ no results...
485-
query_result.set_more_results(False)
486491
return
487492

488493
try:
@@ -496,7 +501,6 @@ def _Dynamic_Next(self, next_request, query_result):
496501
try:
497502
query_result.result_list().append(self.__entity_for_mongo_document(cursor.next()))
498503
except StopIteration:
499-
query_result.set_more_results(False)
500504
return
501505
query_result.set_more_results(True)
502506

test/test_site/index.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,12 @@ class FilterTest(db.Model):
619619
assert FilterTest.all().filter('num >', 10).count() == 2
620620
assert FilterTest.all().filter('num !=', 8).count() == 6
621621

622+
assert FilterTest.all().filter('num <', 10).filter('num >=', 2).count() == 3
623+
assert FilterTest.all().filter('num =', 10).filter('num >=', 2).count() == 1
624+
assert FilterTest.all().filter('num =', 10).filter('num <', 2).count() == 0
625+
assert FilterTest.all().filter('num =', 10).filter('num =', 2).count() == 0
626+
assert FilterTest.all().filter('num =', 10).filter('num =', 10).count() == 1
627+
622628
print 'Test deleting an entity directly using its key...<br/>'
623629
db.delete(key)
624630
assert CountTest.all().count() == 15

0 commit comments

Comments
 (0)