Skip to content

Commit

Permalink
fix: CON-112 - Get tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Baker committed Nov 29, 2017
1 parent 01c1e42 commit 0d4f501
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 4 additions & 0 deletions tests/dereference.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,7 @@ class Room(Document):
room = Room.objects.first().select_related()
self.assertEquals(room.staffs_with_position[0]['staff'], sarah)
self.assertEquals(room.staffs_with_position[1]['staff'], bob)


if __name__ == '__main__':
unittest.main()
35 changes: 19 additions & 16 deletions tests/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class Log(Document):
date = DateTimeField(default=datetime.now)
meta = {
'max_documents': 10,
'max_size': 90000,
'max_size': 25600,
}

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

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

Log.drop_collection()

def test_hint(self):
def test_can_hint_without_breaking_the_query(self):

class BlogPost(Document):
tags = ListField(StringField())
meta = {
'indexes': [
'tags',
],
}

BlogPost.drop_collection()
BlogPost.objects._collection.ensure_index([('tags', pymongo.ASCENDING)])

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

self.assertEquals(BlogPost.objects.count(), 10)
self.assertEquals(BlogPost.objects.hint().count(), 10)
self.assertEquals(BlogPost.objects.hint([('tags', 1)]).count(), 10)
self.assertEquals(
BlogPost.objects.hint([('tags', pymongo.ASCENDING)]).count(),
10)

def test_hint_without_index_will_raise(self):

class BlogPost(Document):
tags = ListField(StringField())

self.assertEquals(BlogPost.objects.hint([('ZZ', 1)]).count(), 10)
BlogPost.drop_collection()
BlogPost.objects._collection.ensure_index([('tags', pymongo.ASCENDING)])

def invalid_index():
list(BlogPost.objects.hint('tags'))
self.assertRaises(pymongo.errors.OperationFailure, invalid_index)
for i in xrange(0, 10):
tags = [("tag %i" % n) for n in xrange(0, i % 2)]
BlogPost(tags=tags).save()

def invalid_index_2():
return list(BlogPost.objects.hint([('tags', 1)]))
self.assertRaises(pymongo.errors.OperationFailure, invalid_index_2)
with self.assertRaises(pymongo.errors.OperationFailure):
self.assertEquals(BlogPost.objects.hint([('ZZ', 1)]).count(), 10)

def test_custom_id_field(self):
"""Ensure that documents may be created with custom primary keys.
Expand Down
4 changes: 4 additions & 0 deletions tests/dynamic_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,7 @@ class Doc(DynamicDocument):
self.assertEquals(doc._get_changed_fields(), ['dict_field.embedded.string_field'])
self.assertEquals(doc._delta(), ({'dict_field.embedded.string_field': 'Hello World'}, {}))


if __name__ == '__main__':
unittest.main()

4 changes: 4 additions & 0 deletions tests/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,7 @@ def bulk_create_author_without_load():
])

self.Author.objects.delete()


if __name__ == '__main__':
unittest.main()

0 comments on commit 0d4f501

Please sign in to comment.