@@ -474,7 +474,7 @@ class Log(Document):
474
474
date = DateTimeField (default = datetime .now )
475
475
meta = {
476
476
'max_documents' : 10 ,
477
- 'max_size' : 90000 ,
477
+ 'max_size' : 25600 ,
478
478
}
479
479
480
480
Log .drop_collection ()
@@ -492,7 +492,7 @@ class Log(Document):
492
492
options = Log .objects ._collection .options ()
493
493
self .assertEqual (options ['capped' ], True )
494
494
self .assertEqual (options ['max' ], 10 )
495
- self .assertEqual (options ['size' ], 90000 )
495
+ self .assertEqual (options ['size' ], 25600 ) # Must be multiple of 256
496
496
497
497
# Check that the document cannot be redefined with different options
498
498
def recreate_log_document ():
@@ -507,35 +507,38 @@ class Log(Document):
507
507
508
508
Log .drop_collection ()
509
509
510
- def test_hint (self ):
510
+ def test_can_hint_without_breaking_the_query (self ):
511
511
512
512
class BlogPost (Document ):
513
513
tags = ListField (StringField ())
514
- meta = {
515
- 'indexes' : [
516
- 'tags' ,
517
- ],
518
- }
519
514
520
515
BlogPost .drop_collection ()
516
+ BlogPost .objects ._collection .ensure_index ([('tags' , pymongo .ASCENDING )])
521
517
522
518
for i in xrange (0 , 10 ):
523
519
tags = [("tag %i" % n ) for n in xrange (0 , i % 2 )]
524
520
BlogPost (tags = tags ).save ()
525
521
526
522
self .assertEquals (BlogPost .objects .count (), 10 )
527
523
self .assertEquals (BlogPost .objects .hint ().count (), 10 )
528
- self .assertEquals (BlogPost .objects .hint ([('tags' , 1 )]).count (), 10 )
524
+ self .assertEquals (
525
+ BlogPost .objects .hint ([('tags' , pymongo .ASCENDING )]).count (),
526
+ 10 )
527
+
528
+ def test_hint_without_index_will_raise (self ):
529
+
530
+ class BlogPost (Document ):
531
+ tags = ListField (StringField ())
529
532
530
- self .assertEquals (BlogPost .objects .hint ([('ZZ' , 1 )]).count (), 10 )
533
+ BlogPost .drop_collection ()
534
+ BlogPost .objects ._collection .ensure_index ([('tags' , pymongo .ASCENDING )])
531
535
532
- def invalid_index ( ):
533
- list ( BlogPost . objects . hint ( 'tags' ))
534
- self . assertRaises ( pymongo . errors . OperationFailure , invalid_index )
536
+ for i in xrange ( 0 , 10 ):
537
+ tags = [( "tag %i" % n ) for n in xrange ( 0 , i % 2 )]
538
+ BlogPost ( tags = tags ). save ( )
535
539
536
- def invalid_index_2 ():
537
- return list (BlogPost .objects .hint ([('tags' , 1 )]))
538
- self .assertRaises (pymongo .errors .OperationFailure , invalid_index_2 )
540
+ with self .assertRaises (pymongo .errors .OperationFailure ):
541
+ self .assertEquals (BlogPost .objects .hint ([('ZZ' , 1 )]).count (), 10 )
539
542
540
543
def test_custom_id_field (self ):
541
544
"""Ensure that documents may be created with custom primary keys.
0 commit comments