def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all() populate_db() self.client = self.app.test_client(use_cookies=True)
if lim > 0: sql = "SELECT `id`, `name`, `password` FROM `users` LIMIT %s" size = cursor.execute(sql, (lim)) if size == 0: return "",500 else: sql = "SELECT `id`, `name`, `password` FROM `users`" cursor.execute(sql) json = cursor.fetchall() header = [x[0] for x in cursor.description] json_data = [] for result in json: json_data.append(dict(zip(header, result))) return jsonify(users=json_data) if __name__ == "__main__": seed = "randomseed" if len(sys.argv) == 2: seed = sys.argv[1] db = pymysql.connect("localhost", username, password, database) with db.cursor() as cursor: populate.populate_db(seed,cursor) db.commit() print("[+] database populated") app.run(host='0.0.0.0',port=80)
text_message = f'\nВсе тесты выполнены идеально!' else: text_message = f"\nВы не ответили ни на один вопрос :с" result_scores.config(text=text_message, font=('Helvetica', 16, 'bold')) new_question = False else: new_question = questions[cur_q.get()] test_task.update_component(new_question) subjects_list.delete(0, END) update_scores_list(subjects_list) WINDOW.after(250, update_current_question) populate_db() WINDOW = Tk() WINDOW.title("Пiдготовчi курси") WINDOW.geometry('640x480') subjects = query_subjects() questions = query_questions(subjects) cur_q = CurrentQuestionTracker() subjects_list = generate_subjects_list(WINDOW, subjects) result_scores = generate_result_scores(WINDOW) update_scores_list(subjects_list) test_task = TestTask(WINDOW, questions[cur_q.get()].subject, questions[cur_q.get()], cur_q)
# named limit. For example, /users?limit=4 should only return the first four # users. # If the paramer given is invalid, then the response code must be 500. @app.route("/users", methods=["GET"]) def contact(): def create_response(rows): return {'users': list(map(itemgetter(0), rows))} with db.cursor() as cursor: limit = request.args.get('limit') if limit: try: cursor.execute('SELECT name FROM users LIMIT %s', int(limit)) except: return 'invalid limit parameter', 500 else: cursor.execute('SELECT name FROM users') json = create_response(cursor.fetchall()) #json = None return jsonify(json), 200 if __name__ == "__main__": db = pymysql.connect("localhost", username, password, database) with db.cursor() as cursor: populate.populate_db(cursor) db.commit() print("[+] database populated") app.run(host='0.0.0.0', port=80)
def create_all(): """Initialize the tables for each model defined in the app""" with db: db.create_tables(tables) populate_db()
def populate(): #Add deafult data to the database populate_db()