def configure(self): """ Configure the db, creating the needed collections and theirs indexes. :return: self """ opt = self.options db_collections = db.collection_names(include_system_collections=False) accounts_collection = opt.accounts_collection sessions_collection = opt.sessions_collection login_attempts_collection = opt.login_attempts_collection user_key_field = opt.user_key_field if accounts_collection not in db_collections: # create the account collection accounts = db.create_collection(accounts_collection) accounts.create_index([(user_key_field, ASCENDING)]) if sessions_collection not in db_collections: # create the sessions collection sessions = db.create_collection(sessions_collection) sessions.create_index([(user_key_field, ASCENDING)]) sessions.create_index([("guid", ASCENDING)]) if login_attempts_collection and login_attempts_collection not in db_collections: # create the login attempts collection login_attempts = db.create_collection(login_attempts_collection) login_attempts.create_index([(user_key_field, ASCENDING)]) return self
def test_store_configuration(self): """ Tests that the Mongo MembershipStore properly creates the collections in the database. """ store = MembershipStore() db_collections = db.collection_names(include_system_collections=False) assert store.options.accounts_collection in db_collections assert store.options.sessions_collection in db_collections if store.options.login_attempts_collection: assert store.options.login_attempts_collection in db_collections
def configure(self): """ Configure the db, creating the needed collections and theirs indexes. :return: self """ opt = self.options db_collections = db.collection_names(include_system_collections=False) messages_collection = opt.messages_collection exceptions_collection = opt.exceptions_collection if messages_collection not in db_collections: # create the messages collection messages = db.create_collection(messages_collection) if exceptions_collection not in db_collections: # create the sessions collection exceptions = db.create_collection(exceptions_collection) return self