Browse Source

增加测试文件

Signed-off-by: binren <zhangbr@elab-plus.com>
binren 4 years ago
parent
commit
489d835b8a
3 changed files with 66 additions and 0 deletions
  1. 43 0
      app_test.py
  2. 12 0
      blue/my_blue_print.py
  3. 11 0
      blue/online_blue.py

+ 43 - 0
app_test.py

@@ -0,0 +1,43 @@
+from flask import Flask
+import sentry_sdk
+from sentry_sdk.integrations.flask import FlaskIntegration
+from apscheduler_elab import Config
+from flask_apscheduler import APScheduler
+import importlib
+import os
+from file_util import FileUtil
+
+
+sentry_sdk.init(
+    dsn="https://e9f173e651684e9080a7b297d51512c7@o382660.ingest.sentry.io/5211871",
+    integrations=[FlaskIntegration()])
+
+
+def create_app():
+    app_instance = Flask(__name__)
+    app.config.from_object(Config())
+    blueprint_list = []
+    path = os.path.dirname(os.path.abspath(__file__)) + r'/blue'
+    file_list = FileUtil.load_file(path)
+    for file_path in file_list:
+        file_name = os.path.split(file_path)[1].split('.')[0]
+        blueprint_list.append(file_name)
+
+    for blueprint in blueprint_list:
+        auto_blueprint_module = importlib.import_module('blue.' + str(blueprint))
+        auto_blueprint = auto_blueprint_module.__dict__[blueprint]
+        app.register_blueprint(auto_blueprint, url_prefix='/' + str(blueprint))
+    return app_instance
+
+
+app = create_app()
+
+
+if __name__ == '__main__':
+    scheduler = APScheduler()
+    scheduler.init_app(app)
+    scheduler.start()
+    app.run(
+        host='0.0.0.0',
+        port=5001
+    )

+ 12 - 0
blue/my_blue_print.py

@@ -0,0 +1,12 @@
+from flask import Blueprint
+
+my_blue_print = Blueprint('my_blue_print',
+                          __name__,
+                          template_folder='templates'
+                          )
+
+
+@my_blue_print.route('/test')
+def test():
+    print('test')
+    print((1/0))

+ 11 - 0
blue/online_blue.py

@@ -0,0 +1,11 @@
+from flask import Blueprint, jsonify
+from mysql_db import MysqlDB
+
+online_blue = Blueprint('online_blue', __name__)
+
+
+@online_blue.route('/online', methods=['POST', 'GET'])
+def online():
+    db = MysqlDB('linshi', 1)
+    result = db.select('select * from report_push_customer_info limit 10')
+    return jsonify(result)