Added CollectionManager, made connection module
All connection-related functions are now in connection.py. Created a ConnectionManager class for interacting with a collection in the database. Top-level document classes have an instance of a ConnectionManager (Document.collection). Defined a 'save' method on top-level document's that uses the collection manager's '_save_document' method to save the document to the database. Added tests for CollectionManagers -- all unit tests now require a valid connection to the database, which is set up in the tests' setUp method.
This commit is contained in:
33
tests/collection.py
Normal file
33
tests/collection.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import unittest
|
||||
import pymongo
|
||||
|
||||
from mongomap.collection import CollectionManager
|
||||
from mongomap import *
|
||||
|
||||
|
||||
class CollectionManagerTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
connect(db='mongotest')
|
||||
|
||||
class Person(Document):
|
||||
name = StringField()
|
||||
age = IntField()
|
||||
self.Person = Person
|
||||
|
||||
def test_initialisation(self):
|
||||
"""Ensure that CollectionManager is correctly initialised.
|
||||
"""
|
||||
class Person(Document):
|
||||
name = StringField()
|
||||
age = IntField()
|
||||
|
||||
self.assertTrue(isinstance(Person.collection, CollectionManager))
|
||||
self.assertEqual(Person.collection._collection_name,
|
||||
Person._meta['collection'])
|
||||
self.assertTrue(isinstance(Person.collection._collection,
|
||||
pymongo.collection.Collection))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user