fix minor styling issue in tests

This commit is contained in:
Bastien Gérard 2019-02-25 22:33:36 +01:00
parent 3cdb5b5db2
commit c60c2ee8d0
13 changed files with 36 additions and 31 deletions

View File

@ -66,7 +66,7 @@ class ClassMethodsTest(unittest.TestCase):
""" """
collection_name = 'person' collection_name = 'person'
self.Person(name='Test').save() self.Person(name='Test').save()
self.assertIn(collection_name, self.db.collection_names()) self.assertIn(collection_name, self.db.collection_names())
self.Person.drop_collection() self.Person.drop_collection()
self.assertNotIn(collection_name, self.db.collection_names()) self.assertNotIn(collection_name, self.db.collection_names())
@ -102,16 +102,16 @@ class ClassMethodsTest(unittest.TestCase):
BlogPost.drop_collection() BlogPost.drop_collection()
BlogPost.ensure_indexes() BlogPost.ensure_indexes()
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []})
BlogPost.ensure_index(['author', 'description']) BlogPost.ensure_index(['author', 'description'])
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [[('author', 1), ('description', 1)]] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': [[('author', 1), ('description', 1)]]})
BlogPost._get_collection().drop_index('author_1_description_1') BlogPost._get_collection().drop_index('author_1_description_1')
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []})
BlogPost._get_collection().drop_index('author_1_title_1') BlogPost._get_collection().drop_index('author_1_title_1')
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [[('author', 1), ('title', 1)]], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [[('author', 1), ('title', 1)]], 'extra': []})
def test_compare_indexes_inheritance(self): def test_compare_indexes_inheritance(self):
""" Ensure that the indexes are properly created and that """ Ensure that the indexes are properly created and that
@ -140,16 +140,16 @@ class ClassMethodsTest(unittest.TestCase):
BlogPost.ensure_indexes() BlogPost.ensure_indexes()
BlogPostWithTags.ensure_indexes() BlogPostWithTags.ensure_indexes()
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []})
BlogPostWithTags.ensure_index(['author', 'tag_list']) BlogPostWithTags.ensure_index(['author', 'tag_list'])
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [[('_cls', 1), ('author', 1), ('tag_list', 1)]] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': [[('_cls', 1), ('author', 1), ('tag_list', 1)]]})
BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tag_list_1') BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tag_list_1')
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []})
BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tags_1') BlogPostWithTags._get_collection().drop_index('_cls_1_author_1_tags_1')
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [[('_cls', 1), ('author', 1), ('tags', 1)]], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [[('_cls', 1), ('author', 1), ('tags', 1)]], 'extra': []})
def test_compare_indexes_multiple_subclasses(self): def test_compare_indexes_multiple_subclasses(self):
""" Ensure that compare_indexes behaves correctly if called from a """ Ensure that compare_indexes behaves correctly if called from a
@ -184,9 +184,9 @@ class ClassMethodsTest(unittest.TestCase):
BlogPostWithTags.ensure_indexes() BlogPostWithTags.ensure_indexes()
BlogPostWithCustomField.ensure_indexes() BlogPostWithCustomField.ensure_indexes()
self.assertEqual(BlogPost.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPost.compare_indexes(), {'missing': [], 'extra': []})
self.assertEqual(BlogPostWithTags.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPostWithTags.compare_indexes(), {'missing': [], 'extra': []})
self.assertEqual(BlogPostWithCustomField.compare_indexes(), { 'missing': [], 'extra': [] }) self.assertEqual(BlogPostWithCustomField.compare_indexes(), {'missing': [], 'extra': []})
@requires_mongodb_gte_26 @requires_mongodb_gte_26
def test_compare_indexes_for_text_indexes(self): def test_compare_indexes_for_text_indexes(self):

View File

@ -863,5 +863,6 @@ class DeltaTest(unittest.TestCase):
self.assertEqual('oops', delta[0]["users.007.rolist"][0]["type"]) self.assertEqual('oops', delta[0]["users.007.rolist"][0]["type"])
self.assertEqual(uinfo.id, delta[0]["users.007.info"]) self.assertEqual(uinfo.id, delta[0]["users.007.info"])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -32,12 +32,12 @@ class TestJson(unittest.TestCase):
string = StringField(db_field='s') string = StringField(db_field='s')
embedded = EmbeddedDocumentField(Embedded, db_field='e') embedded = EmbeddedDocumentField(Embedded, db_field='e')
doc = Doc( string="Hello", embedded=Embedded(string="Inner Hello")) doc = Doc(string="Hello", embedded=Embedded(string="Inner Hello"))
doc_json = doc.to_json(sort_keys=True, use_db_field=False,separators=(',', ':')) doc_json = doc.to_json(sort_keys=True, use_db_field=False, separators=(',', ':'))
expected_json = """{"embedded":{"string":"Inner Hello"},"string":"Hello"}""" expected_json = """{"embedded":{"string":"Inner Hello"},"string":"Hello"}"""
self.assertEqual( doc_json, expected_json) self.assertEqual(doc_json, expected_json)
def test_json_simple(self): def test_json_simple(self):

View File

@ -578,5 +578,6 @@ class FileTest(MongoDBTestCase):
self.assertEqual(marmot.photos[0].foo, 'bar') self.assertEqual(marmot.photos[0].foo, 'bar')
self.assertEqual(marmot.photos[0].get().length, 8313) self.assertEqual(marmot.photos[0].get().length, 8313)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -48,6 +48,7 @@ class PickleSignalsTest(Document):
def post_delete(self, sender, document, **kwargs): def post_delete(self, sender, document, **kwargs):
pickled = pickle.dumps(document) pickled = pickle.dumps(document)
signals.post_save.connect(PickleSignalsTest.post_save, sender=PickleSignalsTest) signals.post_save.connect(PickleSignalsTest.post_save, sender=PickleSignalsTest)
signals.post_delete.connect(PickleSignalsTest.post_delete, sender=PickleSignalsTest) signals.post_delete.connect(PickleSignalsTest.post_delete, sender=PickleSignalsTest)

View File

@ -208,7 +208,7 @@ class OnlyExcludeAllTest(unittest.TestCase):
BlogPost.drop_collection() BlogPost.drop_collection()
post = BlogPost(content='Had a good coffee today...', various={'test_dynamic':{'some': True}}) post = BlogPost(content='Had a good coffee today...', various={'test_dynamic': {'some': True}})
post.author = User(name='Test User') post.author = User(name='Test User')
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')] post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
post.save() post.save()
@ -413,7 +413,6 @@ class OnlyExcludeAllTest(unittest.TestCase):
numbers = Numbers.objects.fields(embedded__n={"$slice": [-5, 10]}).get() numbers = Numbers.objects.fields(embedded__n={"$slice": [-5, 10]}).get()
self.assertEqual(numbers.embedded.n, [-5, -4, -3, -2, -1]) self.assertEqual(numbers.embedded.n, [-5, -4, -3, -2, -1])
def test_exclude_from_subclasses_docs(self): def test_exclude_from_subclasses_docs(self):
class Base(Document): class Base(Document):
@ -436,5 +435,6 @@ class OnlyExcludeAllTest(unittest.TestCase):
self.assertRaises(LookUpError, Base.objects.exclude, "made_up") self.assertRaises(LookUpError, Base.objects.exclude, "made_up")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -534,11 +534,11 @@ class GeoQueriesTest(MongoDBTestCase):
Location.drop_collection() Location.drop_collection()
Location(loc=[1,2]).save() Location(loc=[1, 2]).save()
loc = Location.objects.as_pymongo()[0] loc = Location.objects.as_pymongo()[0]
self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [1, 2]}) self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [1, 2]})
Location.objects.update(set__loc=[2,1]) Location.objects.update(set__loc=[2, 1])
loc = Location.objects.as_pymongo()[0] loc = Location.objects.as_pymongo()[0]
self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [2, 1]}) self.assertEqual(loc["loc"], {"type": "Point", "coordinates": [2, 1]})

View File

@ -6,10 +6,12 @@ from mongoengine.connection import connect
__author__ = 'stas' __author__ = 'stas'
class Person(Document): class Person(Document):
name = StringField() name = StringField()
age = IntField() age = IntField()
class TestQuerysetPickable(unittest.TestCase): class TestQuerysetPickable(unittest.TestCase):
""" """
Test for adding pickling support for QuerySet instances Test for adding pickling support for QuerySet instances
@ -18,7 +20,7 @@ class TestQuerysetPickable(unittest.TestCase):
def setUp(self): def setUp(self):
super(TestQuerysetPickable, self).setUp() super(TestQuerysetPickable, self).setUp()
connection = connect(db="test") #type: pymongo.mongo_client.MongoClient connection = connect(db="test") # type: pymongo.mongo_client.MongoClient
connection.drop_database("test") connection.drop_database("test")
@ -27,7 +29,6 @@ class TestQuerysetPickable(unittest.TestCase):
age=21 age=21
) )
def test_picke_simple_qs(self): def test_picke_simple_qs(self):
qs = Person.objects.all() qs = Person.objects.all()
@ -46,10 +47,10 @@ class TestQuerysetPickable(unittest.TestCase):
self.assertEqual(qs.count(), loadedQs.count()) self.assertEqual(qs.count(), loadedQs.count())
#can update loadedQs # can update loadedQs
loadedQs.update(age=23) loadedQs.update(age=23)
#check # check
self.assertEqual(Person.objects.first().age, 23) self.assertEqual(Person.objects.first().age, 23)
def test_pickle_support_filtration(self): def test_pickle_support_filtration(self):
@ -70,7 +71,7 @@ class TestQuerysetPickable(unittest.TestCase):
self.assertEqual(loaded.count(), 2) self.assertEqual(loaded.count(), 2)
self.assertEqual(loaded.filter(name="Bob").first().age, 23) self.assertEqual(loaded.filter(name="Bob").first().age, 23)

View File

@ -275,7 +275,6 @@ class QTest(unittest.TestCase):
with self.assertRaises(InvalidQueryError): with self.assertRaises(InvalidQueryError):
self.Person.objects.filter('user1') self.Person.objects.filter('user1')
def test_q_regex(self): def test_q_regex(self):
"""Ensure that Q objects can be queried using regexes. """Ensure that Q objects can be queried using regexes.
""" """

View File

@ -99,11 +99,11 @@ class ConnectionTest(unittest.TestCase):
conn = get_connection() conn = get_connection()
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)
connect(host=['mongodb://localhost'], is_mock=True, alias='testdb2') connect(host=['mongodb://localhost'], is_mock=True, alias='testdb2')
conn = get_connection('testdb2') conn = get_connection('testdb2')
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)
connect(host=['localhost'], is_mock=True, alias='testdb3') connect(host=['localhost'], is_mock=True, alias='testdb3')
conn = get_connection('testdb3') conn = get_connection('testdb3')
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)
@ -111,11 +111,11 @@ class ConnectionTest(unittest.TestCase):
conn = get_connection('testdb4') conn = get_connection('testdb4')
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)
connect(host=['mongodb://localhost:27017', 'mongodb://localhost:27018'], is_mock=True, alias='testdb5') connect(host=['mongodb://localhost:27017', 'mongodb://localhost:27018'], is_mock=True, alias='testdb5')
conn = get_connection('testdb5') conn = get_connection('testdb5')
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)
connect(host=['localhost:27017', 'localhost:27018'], is_mock=True, alias='testdb6') connect(host=['localhost:27017', 'localhost:27018'], is_mock=True, alias='testdb6')
conn = get_connection('testdb6') conn = get_connection('testdb6')
self.assertIsInstance(conn, mongomock.MongoClient) self.assertIsInstance(conn, mongomock.MongoClient)

View File

@ -302,5 +302,6 @@ class ContextManagersTest(unittest.TestCase):
_ = db.system.indexes.find_one() # queries on db.system.indexes are ignored as well _ = db.system.indexes.find_one() # queries on db.system.indexes are ignored as well
self.assertEqual(q, 1) self.assertEqual(q, 1)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -47,5 +47,6 @@ class ConnectionTest(unittest.TestCase):
self.assertEqual(conn.read_preference, READ_PREF) self.assertEqual(conn.read_preference, READ_PREF)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -39,7 +39,6 @@ class SignalTests(unittest.TestCase):
def post_init(cls, sender, document, **kwargs): def post_init(cls, sender, document, **kwargs):
signal_output.append('post_init signal, %s, document._created = %s' % (document, document._created)) signal_output.append('post_init signal, %s, document._created = %s' % (document, document._created))
@classmethod @classmethod
def pre_save(cls, sender, document, **kwargs): def pre_save(cls, sender, document, **kwargs):
signal_output.append('pre_save signal, %s' % document) signal_output.append('pre_save signal, %s' % document)
@ -247,7 +246,7 @@ class SignalTests(unittest.TestCase):
def load_existing_author(): def load_existing_author():
a = self.Author(name='Bill Shakespeare') a = self.Author(name='Bill Shakespeare')
a.save() a.save()
self.get_signal_output(lambda: None) # eliminate signal output self.get_signal_output(lambda: None) # eliminate signal output
a1 = self.Author.objects(name='Bill Shakespeare')[0] a1 = self.Author.objects(name='Bill Shakespeare')[0]
self.assertEqual(self.get_signal_output(create_author), [ self.assertEqual(self.get_signal_output(create_author), [
@ -431,5 +430,6 @@ class SignalTests(unittest.TestCase):
{} {}
]) ])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()