def run(): """Modified the method to activate session """ settings.update(json.load(file(sys.argv[1]))) cherrypy.quickstart(Root(settings), "/", {'/': { 'tools.sessions.on': True }})
def app(): global _app settings.update({"url": "mongodb://localhost:27017/test_crunch_fitness"}) if _app is None: _app = webtest.TestApp(get_app()) load_data(_here + '/../../cr-db/tests/data/users.json', settings, clear=True) return _app
def load_data(settings=None, clear=None): if settings is None: settings = global_settings global_settings.update(json.load(open(sys.argv[1]))) db = connect(settings) if clear: db.users.remove() with open(users_filename) as users_file: users = json.load(users_file) for user in users: db.users.insert(user)
def load_data(filename, settings=None, clear=None): if settings is None: settings = global_settings global_settings.update(json.load(file(sys.argv[1]))) db = connect(settings) obj_name = os.path.basename(filename).split('.')[0] collection = getattr(db, obj_name) if clear: collection.remove() with file(filename) as the_file: objs = json.load(the_file) for obj in objs: collection.insert(obj)
distance_list.append(km) geo_json = { 'minimum': round(min(distance_list), 3), 'maximum': round(max(distance_list), 3), 'average': round(np.average(distance_list), 3), 'std. deviation': round(np.std(distance_list), 3), 'unit measured': 'km' } return json.dumps(geo_json) except KeyError: raise cherrypy.HTTPRedirect("/login") def run(): """Modified the method to activate session """ settings.update(json.load(file(sys.argv[1]))) cherrypy.quickstart(Root(settings), "/", {'/': { 'tools.sessions.on': True }}) if __name__ == "__main__": settings.update({'url': "mongodb://localhost:27017/test_crunch_fitness"}) cherrypy.quickstart(Root(settings), "/", {'/': { 'tools.sessions.on': True }})
response['Minimum distance'] = min_d response['Average distance'] = avg_d response['Standard deviation'] = std_d return response def user_verify(self, username, password): """ Simply checks if a user with provided email and pass exists in db :param username: User email :param password: User pass :return: True if user found """ users = self.db.users user = users.find_one({"email": username}) if user: password = hashlib.sha1(password.encode()).hexdigest() return password == user['hash'] return False if __name__ == '__main__': config_root = { '/': { 'tools.crunch.on': True, 'tools.sessions.on': True, 'tools.sessions.name': 'crunch', } } settings.update(json.load(open(sys.argv[1]))) main = Root(settings) cherrypy.quickstart(main, '/', config=config_root)
def run(): settings.update(json.load(file(sys.argv[1]))) cherrypy.quickstart(Root(settings))
def setup_method(self, method): settings.update( {"url": "mongodb://localhost:27017/test_crunch_fitness"}) self.root = Root(settings)
def app(): global _app settings.update({"url": "mongodb://localhost:27017/test_crunch_fitness"}) if _app is None: _app = webtest.TestApp(get_app()) return _app