Skip to content

Commit 0d4f501

Browse files
author
Marcus Baker
committed
fix: CON-112 - Get tests passing
1 parent 01c1e42 commit 0d4f501

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

tests/dereference.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,7 @@ class Room(Document):
659659
room = Room.objects.first().select_related()
660660
self.assertEquals(room.staffs_with_position[0]['staff'], sarah)
661661
self.assertEquals(room.staffs_with_position[1]['staff'], bob)
662+
663+
664+
if __name__ == '__main__':
665+
unittest.main()

tests/document.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ class Log(Document):
474474
date = DateTimeField(default=datetime.now)
475475
meta = {
476476
'max_documents': 10,
477-
'max_size': 90000,
477+
'max_size': 25600,
478478
}
479479

480480
Log.drop_collection()
@@ -492,7 +492,7 @@ class Log(Document):
492492
options = Log.objects._collection.options()
493493
self.assertEqual(options['capped'], True)
494494
self.assertEqual(options['max'], 10)
495-
self.assertEqual(options['size'], 90000)
495+
self.assertEqual(options['size'], 25600) # Must be multiple of 256
496496

497497
# Check that the document cannot be redefined with different options
498498
def recreate_log_document():
@@ -507,35 +507,38 @@ class Log(Document):
507507

508508
Log.drop_collection()
509509

510-
def test_hint(self):
510+
def test_can_hint_without_breaking_the_query(self):
511511

512512
class BlogPost(Document):
513513
tags = ListField(StringField())
514-
meta = {
515-
'indexes': [
516-
'tags',
517-
],
518-
}
519514

520515
BlogPost.drop_collection()
516+
BlogPost.objects._collection.ensure_index([('tags', pymongo.ASCENDING)])
521517

522518
for i in xrange(0, 10):
523519
tags = [("tag %i" % n) for n in xrange(0, i % 2)]
524520
BlogPost(tags=tags).save()
525521

526522
self.assertEquals(BlogPost.objects.count(), 10)
527523
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())
529532

530-
self.assertEquals(BlogPost.objects.hint([('ZZ', 1)]).count(), 10)
533+
BlogPost.drop_collection()
534+
BlogPost.objects._collection.ensure_index([('tags', pymongo.ASCENDING)])
531535

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()
535539

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)
539542

540543
def test_custom_id_field(self):
541544
"""Ensure that documents may be created with custom primary keys.

tests/dynamic_document.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,7 @@ class Doc(DynamicDocument):
468468
self.assertEquals(doc._get_changed_fields(), ['dict_field.embedded.string_field'])
469469
self.assertEquals(doc._delta(), ({'dict_field.embedded.string_field': 'Hello World'}, {}))
470470

471+
472+
if __name__ == '__main__':
473+
unittest.main()
474+

tests/signals.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,7 @@ def bulk_create_author_without_load():
230230
])
231231

232232
self.Author.objects.delete()
233+
234+
235+
if __name__ == '__main__':
236+
unittest.main()

0 commit comments

Comments
 (0)