def test_init_later(self): self.db = MongoKit() self.assertRaises(RuntimeError, self.db.connect) self.db.init_app(self.app) self.db.connect() assert self.db.connected
def setUp(self): db = 'flask_testing_auth' conn = Connection() conn[db].add_user('test', 'test') self.app = create_app() self.app.config['TESTING'] = True self.app.config['MONGODB_DATABASE'] = db self.db = MongoKit(self.app)
def setUp(self): self.app_1 = create_app() self.app_1.config['MONGODB_DATABASE'] = 'app_1' self.app_2 = create_app() self.app_2.config['MONGODB_DATABASE'] = 'app_2' assert self.app_1 != self.app_2 self.db = MongoKit() self.db.init_app(self.app_1) self.db.init_app(self.app_2)
__collection__ = 'posts' structure = { 'title': basestring, 'body': basestring, 'date_creation': datetime, 'rank': int, } required_fields = ['title', 'date_creation'] default_values = { 'rank': 0, 'date_creation': datetime.utcnow } use_dot_notation = True db = MongoKit(app) db.register([BlogPost]) def get_rank(): u = int(random.random()*100000) return u @app.route('/') def home(): posts = db.posts.find() return render_template('home.html', posts=posts) @app.route('/add', methods=['GET','POST']) def add(): if request.method == 'POST': post = db.BlogPost()
def str2bool(v): return v.lower() in ("yes", "true", "t", "1") # app = Flask(__name__) app.config['MONGODB_HOST'] = os.environ.get('MONGODB_HOST','194.177.192.227') app.config['MONGODB_USERNAME'] = os.environ.get('MONGODB_USERNAME',None) app.config['MONGODB_PASSWORD'] = os.environ.get('MONGODB_PASSWORD',None) app.config['MONGODB_PORT'] = int(os.environ.get('MONGODB_PORT','27017')) app.config['MONGODB_DATABASE'] = os.environ.get('MONGODB_DATABASE','faqs') # app.config['SERVER_NAME'] = os.environ.get('SERVER_NAME','localhost:5000') app_port = int(os.environ.get('APP_PORT','5000')) app.config['DEBUG'] = str2bool(os.environ.get('DEBUG','True')) CORS(app) mongo = MongoKit(app) mongo.register([Topic,Question,Page,PageHelpContent]) #=========== # TOPICS #=========== def delete_topic_questions(topic): # pprint(topic) questions = mongo.Question.find({"topics" : topic._id}) for question in questions: question.topics.remove(topic._id) if len(question.topics)==0 : question.delete()
def test_init_immediately(self): self.db = MongoKit(self.app) self.db.connect() assert self.db.connected
def setUp(self): self.app = create_app() self.db = MongoKit(self.app)
def setUp(self): self.app = create_app() self.db = MongoKit(self.app) self.ctx = self.app.app_context() self.ctx.push()
def setUp(self): self.app = create_app() self.db = MongoKit(self.app) self.ctx = self.app.test_request_context('/') self.ctx.push()
} required_fields = ['name', 'college_id', 'email'] default_values = {'time': datetime.now()} use_dot_notation = True class Attendance(Document): __collection__ = 'pypals' structure = { 'college_id': unicode, 'talks_attended': list } required_fields = ['college_id', 'talks_attended'] default_values = {'talks_attended': []} use_dot_notation = True conn = MongoKit(app) conn.register(User) conn.register(Attendance) @app.route("/") def main(): return redirect(u'/\u03BCpy') @app.route("/repo") def repo(): return redirect('https://github.com/PyPals') @app.route(u'/\u03BCpy') def mu_py(): return render_template('index.html', title="MUPy 2018", subtitle="MUPy")