Fixing test
This commit is contained in:
parent
fbe1901e65
commit
216f15602b
@ -2532,15 +2532,17 @@ class DocumentTest(unittest.TestCase):
|
|||||||
""" DB Alias tests """
|
""" DB Alias tests """
|
||||||
# mongoenginetest - Is default connection alias from setUp()
|
# mongoenginetest - Is default connection alias from setUp()
|
||||||
# Register Aliases
|
# Register Aliases
|
||||||
register_connection('testdb-1', "mongoenginetest2" )
|
register_connection('testdb-1', 'mongoenginetest2')
|
||||||
register_connection('testdb-2', "mongoenginetest3" )
|
register_connection('testdb-2', 'mongoenginetest3')
|
||||||
register_connection('testdb-3', 'mongoenginetest4')
|
register_connection('testdb-3', 'mongoenginetest4')
|
||||||
|
|
||||||
class User(Document):
|
class User(Document):
|
||||||
name = StringField()
|
name = StringField()
|
||||||
|
meta = {"db_alias": "testdb-1"}
|
||||||
|
|
||||||
class Book(Document):
|
class Book(Document):
|
||||||
name = StringField()
|
name = StringField()
|
||||||
meta = {"db_alias" : "testdb-1" }
|
meta = {"db_alias": "testdb-2"}
|
||||||
|
|
||||||
# Drops
|
# Drops
|
||||||
User.drop_collection()
|
User.drop_collection()
|
||||||
@ -2558,7 +2560,7 @@ class DocumentTest(unittest.TestCase):
|
|||||||
class AuthorBooks(Document):
|
class AuthorBooks(Document):
|
||||||
author = ReferenceField(User)
|
author = ReferenceField(User)
|
||||||
book = ReferenceField(Book)
|
book = ReferenceField(Book)
|
||||||
meta = {"db_alias" : "testdb-2" }
|
meta = {"db_alias": "testdb-3"}
|
||||||
|
|
||||||
# Drops
|
# Drops
|
||||||
AuthorBooks.drop_collection()
|
AuthorBooks.drop_collection()
|
||||||
@ -2569,25 +2571,18 @@ class DocumentTest(unittest.TestCase):
|
|||||||
self.assertEqual(AuthorBooks.objects.first(), ab)
|
self.assertEqual(AuthorBooks.objects.first(), ab)
|
||||||
self.assertEqual(AuthorBooks.objects.first().book, hp)
|
self.assertEqual(AuthorBooks.objects.first().book, hp)
|
||||||
self.assertEqual(AuthorBooks.objects.first().author, bob)
|
self.assertEqual(AuthorBooks.objects.first().author, bob)
|
||||||
|
|
||||||
self.assertEqual(AuthorBooks.objects.filter(author=bob).first(), ab)
|
self.assertEqual(AuthorBooks.objects.filter(author=bob).first(), ab)
|
||||||
self.assertEqual(AuthorBooks.objects.filter(book=hp).first(), ab)
|
self.assertEqual(AuthorBooks.objects.filter(book=hp).first(), ab)
|
||||||
|
|
||||||
# DB Alias
|
# DB Alias
|
||||||
self.assertEqual( User._get_db() , get_db())
|
self.assertEqual(User._get_db(), get_db("testdb-1"))
|
||||||
self.assertEqual( Book._get_db() , get_db("testdb-1"))
|
self.assertEqual(Book._get_db(), get_db("testdb-2"))
|
||||||
self.assertEqual( AuthorBooks._get_db() , get_db("testdb-2"))
|
self.assertEqual(AuthorBooks._get_db(), get_db("testdb-3"))
|
||||||
|
|
||||||
# Collections
|
# Collections
|
||||||
self.assertEqual( User._get_collection() , get_db()[User._get_collection_name()] )
|
self.assertEqual(User._get_collection(), get_db("testdb-1")[User._get_collection_name()])
|
||||||
self.assertEqual(Book._get_collection(), get_db("testdb-2")[Book._get_collection_name()])
|
self.assertEqual(Book._get_collection(), get_db("testdb-2")[Book._get_collection_name()])
|
||||||
self.assertEqual( AuthorBooks._get_collection() , get_db("testdb-2")[AuthorBooks._get_collection_name()] )
|
self.assertEqual(AuthorBooks._get_collection(), get_db("testdb-3")[AuthorBooks._get_collection_name()])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_db_ref_usage(self):
|
def test_db_ref_usage(self):
|
||||||
""" DB Ref usage in __raw__ queries """
|
""" DB Ref usage in __raw__ queries """
|
||||||
@ -2604,10 +2599,10 @@ class DocumentTest(unittest.TestCase):
|
|||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
# Drops
|
# Drops
|
||||||
User.drop_collection()
|
User.drop_collection()
|
||||||
Book.drop_collection()
|
Book.drop_collection()
|
||||||
@ -2622,16 +2617,16 @@ class DocumentTest(unittest.TestCase):
|
|||||||
peter = User.objects.create(name = "Peter")
|
peter = User.objects.create(name = "Peter")
|
||||||
|
|
||||||
# Bob
|
# Bob
|
||||||
Book.objects.create( name = "1", author = bob, extra = {"a": bob.to_dbref(), "b" : [karl.to_dbref(), susan.to_dbref(),] } )
|
Book.objects.create(name = "1", author = bob, extra = {"a": bob.to_dbref(), "b" : [karl.to_dbref(), susan.to_dbref()]} )
|
||||||
Book.objects.create(name = "2", author = bob, extra = {"a": bob.to_dbref(), "b" : karl.to_dbref()} )
|
Book.objects.create(name = "2", author = bob, extra = {"a": bob.to_dbref(), "b" : karl.to_dbref()} )
|
||||||
Book.objects.create(name = "3", author = bob, extra = {"a": bob.to_dbref(), "c" : [jon.to_dbref(), peter.to_dbref()] })
|
Book.objects.create(name = "3", author = bob, extra = {"a": bob.to_dbref(), "c" : [jon.to_dbref(), peter.to_dbref()] })
|
||||||
Book.objects.create( name = "4", author = bob,)
|
Book.objects.create(name = "4", author = bob)
|
||||||
|
|
||||||
# Jon
|
# Jon
|
||||||
Book.objects.create( name = "5", author = jon,)
|
Book.objects.create(name = "5", author = jon)
|
||||||
Book.objects.create( name = "6", author = peter,)
|
Book.objects.create(name = "6", author = peter)
|
||||||
Book.objects.create( name = "7", author = jon,)
|
Book.objects.create(name = "7", author = jon)
|
||||||
Book.objects.create( name = "8", author = jon,)
|
Book.objects.create(name = "8", author = jon)
|
||||||
Book.objects.create(name = "9", author = jon, extra = {"a": peter.to_dbref()})
|
Book.objects.create(name = "9", author = jon, extra = {"a": peter.to_dbref()})
|
||||||
|
|
||||||
# Checks
|
# Checks
|
||||||
@ -2642,6 +2637,7 @@ class DocumentTest(unittest.TestCase):
|
|||||||
Q(author = bob) |
|
Q(author = bob) |
|
||||||
Q(extra__b = bob ) )] ) ,
|
Q(extra__b = bob ) )] ) ,
|
||||||
"1,2,3,4" )
|
"1,2,3,4" )
|
||||||
|
|
||||||
# Susan & Karl related books
|
# Susan & Karl related books
|
||||||
self.assertEqual(u",".join([str(b) for b in Book.objects.filter(
|
self.assertEqual(u",".join([str(b) for b in Book.objects.filter(
|
||||||
Q(extra__a__all = [karl, susan] ) |
|
Q(extra__a__all = [karl, susan] ) |
|
||||||
@ -2657,7 +2653,5 @@ class DocumentTest(unittest.TestCase):
|
|||||||
) ] ) , "1,2" )
|
) ] ) , "1,2" )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user