TG-35 : Test de la connexion à la BDD
This commit is contained in:
		| @@ -22,6 +22,7 @@ class Prod(Config): | |||||||
| class Debug(Config): | class Debug(Config): | ||||||
|     DEBUG = True |     DEBUG = True | ||||||
|     SESSION_COOKIE_SECURE = False |     SESSION_COOKIE_SECURE = False | ||||||
|  |     SQLALCHEMY_DATABASE_URI = 'mysql://ola:ola@localhost/OLA' | ||||||
|  |  | ||||||
|  |  | ||||||
| class Test(Config): | class Test(Config): | ||||||
|   | |||||||
| @@ -1,10 +1,11 @@ | |||||||
|  | import importlib | ||||||
| from datetime import timedelta | from datetime import timedelta | ||||||
|  |  | ||||||
| from flask import Flask, session | from flask import Flask, session | ||||||
| from flask_restful import Api | from flask_restful import Api | ||||||
| from flask_sqlalchemy import SQLAlchemy | from flask_sqlalchemy import SQLAlchemy | ||||||
|  | from sqlalchemy import create_engine | ||||||
| import importlib | from sqlalchemy.ext.automap import automap_base | ||||||
|  |  | ||||||
|  |  | ||||||
| def configure_app(config="prod"): | def configure_app(config="prod"): | ||||||
| @@ -32,6 +33,9 @@ configure_app() | |||||||
|  |  | ||||||
| # SQLAlchemy | # SQLAlchemy | ||||||
| db = SQLAlchemy(app) | db = SQLAlchemy(app) | ||||||
|  | Base = automap_base() | ||||||
|  | engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"]) | ||||||
|  | Base.prepare(engine, reflect=True) | ||||||
|  |  | ||||||
| # RestFul Flask | # RestFul Flask | ||||||
| api = Api(app) | api = Api(app) | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								backend/app/model.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								backend/app/model.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | from backend.app.core import Base | ||||||
|  |  | ||||||
|  | USER = Base.classes.user | ||||||
|  | SETTINGS = Base.classes.settings | ||||||
|  | HASHTABLE = Base.classes.hashtable | ||||||
|  | GROUP = Base.classes.group | ||||||
|  | GROUP_CONTENT = Base.classes.group_content | ||||||
|  | PERIOD = Base.classes.period | ||||||
|  | LIVRET = Base.classes.livret | ||||||
| @@ -1,15 +1,13 @@ | |||||||
| import argparse | import argparse | ||||||
|  | import importlib | ||||||
| import os | import os | ||||||
|  |  | ||||||
| import unittest | import unittest | ||||||
| import warnings | import warnings | ||||||
|  |  | ||||||
| from flask_migrate import Migrate, MigrateCommand |  | ||||||
| from flask_script import Manager, Command | from flask_script import Manager, Command | ||||||
| from flask_script import prompt_bool | from flask_script import prompt_bool | ||||||
|  |  | ||||||
| from backend.app.core import app, db, configure_app | from backend.app.core import configure_app | ||||||
|  |  | ||||||
|  |  | ||||||
| warnings.simplefilter('ignore') | warnings.simplefilter('ignore') | ||||||
|  |  | ||||||
| @@ -24,16 +22,15 @@ if args.debug: | |||||||
| if args.test: | if args.test: | ||||||
|     configure_app(config="test") |     configure_app(config="test") | ||||||
|  |  | ||||||
| migrate = Migrate(app, db) | db = importlib.import_module("db", "backend.app.core") | ||||||
|  | app = importlib.import_module("app", "backend.app.core") | ||||||
|  |  | ||||||
| manager = Manager(app) | manager = Manager(app) | ||||||
| manager.add_option("-d", "--debug", | manager.add_option("-d", "--debug", | ||||||
|                    action="store_true", dest="debug", required=False) |                    action="store_true", dest="debug", required=False) | ||||||
| manager.add_option("-t", "--test", | manager.add_option("-t", "--test", | ||||||
|                    action="store_true", dest="test", required=False) |                    action="store_true", dest="test", required=False) | ||||||
|  |  | ||||||
| # migrations : python manage.py db to show usage |  | ||||||
| manager.add_command('db', MigrateCommand) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class SeedDB(Command): | class SeedDB(Command): | ||||||
|     """Seed the db """ |     """Seed the db """ | ||||||
| @@ -56,6 +53,17 @@ class DropDB(Command): | |||||||
| manager.add_command('dropdb', DropDB()) | manager.add_command('dropdb', DropDB()) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class CheckDB(Command): | ||||||
|  |     """Print database structure""" | ||||||
|  |  | ||||||
|  |     def run(self): | ||||||
|  |         print("List of parsed tables:") | ||||||
|  |         print(db.metadata.tables.keys()) | ||||||
|  |  | ||||||
|  |  | ||||||
|  | manager.add_command('checkdb', CheckDB()) | ||||||
|  |  | ||||||
|  |  | ||||||
| class RunTests(Command): | class RunTests(Command): | ||||||
|     """Seed the db """ |     """Seed the db """ | ||||||
|     def run(self): |     def run(self): | ||||||
|   | |||||||
| @@ -5,3 +5,4 @@ flask-migrate < 2.1 | |||||||
| flask-bootstrap < 3.4 | flask-bootstrap < 3.4 | ||||||
| flask-restful < 0.4 | flask-restful < 0.4 | ||||||
| passlib < 1.8 | passlib < 1.8 | ||||||
|  | mysqlclient < 1.4 | ||||||
		Reference in New Issue
	
	Block a user