#NEWLINE# @ pytest . fixture ( ) #NEWLINE# def mongoengine_datastore( request , app ) : #NEWLINE# #INDENT# from flask_mongoengine import MongoEngine #NEWLINE# db_name = ( 'flask_security_test_%s' % str ( time . time ( ) ) . replace ( '.' , '_' ) ) #NEWLINE# app . config [ 'MONGODB_SETTINGS' ] = { #NEWLINE# #INDENT# 'db' : db_name , #NEWLINE# 'host' : 'localhost' , #NEWLINE# 'port' : 27017 , #NEWLINE# 'alias' : db_name , #NEWLINE# #UNINDENT# } #NEWLINE# db = MongoEngine ( app ) #NEWLINE# class Role ( db . Document , RoleMixin ) : #NEWLINE# #INDENT# name = db . StringField ( required = True , unique = True , max_length = 80 ) #NEWLINE# description = db . StringField ( max_length = 255 ) #NEWLINE# meta = { #NEWLINE# #INDENT# 'db_alias' : db_name , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# class User ( db . Document , UserMixin ) : #NEWLINE# #INDENT# email = db . StringField ( unique = True , max_length = 255 ) #NEWLINE# username = db . StringField ( max_length = 255 ) #NEWLINE# password = db . StringField ( required = False , max_length = 255 ) #NEWLINE# last_login_at = db . DateTimeField ( ) #NEWLINE# current_login_at = db . DateTimeField ( ) #NEWLINE# last_login_ip = db . StringField ( max_length = 100 ) #NEWLINE# current_login_ip = db . StringField ( max_length = 100 ) #NEWLINE# login_count = db . IntField ( ) #NEWLINE# active = db . BooleanField ( default = True ) #NEWLINE# confirmed_at = db . DateTimeField ( ) #NEWLINE# roles = db . ListField ( db . ReferenceField ( Role ) , default = [ ] ) #NEWLINE# meta = { #NEWLINE# #INDENT# 'db_alias' : db_name , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# request . addfinalizer ( ( lambda : db . connection . drop_database ( db_name ) ) ) #NEWLINE# return MongoEngineUserDatastore ( db , User , Role )