def do_admin_login(): if request.method == "POST": POST_USERNAME = str(request.form['username']) POST_PASSWORD = str(request.form['password']) db = Db() engine = db.create_session() # Base = declarative_base() Session = sessionmaker(bind=engine) s = Session() query = s.query(User).filter(User.username.in_([POST_USERNAME]), User.password.in_([POST_PASSWORD])) result = query.first() if result: session['logged_in'] = True # session['nombre']=result.nombre return home() else: return render_template("errors_users.html") else: return redirect(url_for('controller_module.home'))
def create_app(): app_flask = Flask(__name__) secret = secrets.token_urlsafe(32) app_flask.secret_key = secret app_flask.config.from_object('src.custom_config.DevelopmentConfig') # path = src.config['PATH_CONFIG'] os.environ['PATH_CONFIG']='./config/Dashboard_dev.yaml' yml = init_properties(os.environ['PATH_CONFIG']) PropertiesDb(yml['db']) PropertiesGenerales(yml['generales']) PropertiesDf(yml['df']) PropertiesSQL(yml['sql']) PropertiesQueries(yml['queries']) PropertiesQueriesHistorico(yml['queries_historicos']) PropertiesDemanda(yml['queries_distribucion_demanda']) PropertiesTendencia(yml['queries_tendencia_venta']) PropertiesEstancia(yml['queries_estancia']) PropertiesUsuario(yml['nuevo_usuario']) PropertiesCostos(yml['costos']) app_flask.register_blueprint(controller_module) app_flask.register_blueprint(errors) db = Db() db.create_session() log.info("Empieza la aplicacion") return app_flask
def test_exception_if_table_does_not_exist(self): table = mock.Mock(spec=Table) table.name = 'users' db = Db([table]) with self.assertRaises(Exception): db.insert('despacito', id=2)
def test_insert(self): table = mock.Mock(spec=Table) table.name = 'users' db = Db([table]) db.insert('users', id=2, name='Roger') table.insert.assert_called_once_with(id=2, name='Roger')
def setUp(self): migrate = Migration('amity_test') migrate.drop() migrate.install() self.db = Db('amity_test') self.data = { 'firstname':'sunday', 'lastname':'Nwuguru', 'allocated':1, 'living_space':1 } self.db.table_name = 'person'
def test_export(self): table = mock.Mock(spec=Table) table.name = 'users' table.export.return_value = [ {'id': 1, 'name': 'Roger'}, {'id': 2, 'name': 'Patrick'} ] db = Db([table]) self.assertEqual(db.export(), [ {'users': [ {'id': 1, 'name': 'Roger'}, {'id': 2, 'name': 'Patrick'} ]} ])
def default_database(): """ Set up local database (localhost) Test if a local Cassandra instance is available for testing. If not use mock data to run tests. """ global DB # pylint: disable=global-statement DB = Db() if DB.check_connection(): # Delete existing keyspaces sel_stmt = "SELECT keyspace_name FROM system_schema.keyspaces" rows = DB.exec_query(sel_stmt) keyspace_names = [ row.get("keyspace_name") for row in rows if not row.get("keyspace_name").startswith("system") ] for keyspace in keyspace_names: DB.exec_query("DROP KEYSPACE IF EXISTS \"{}\"".format(keyspace)) # Populate instance with sample schemas with open("./tests/setup/cql/create_excalibur.cql", "r") as f: cmd_stmt = f.read() cmds = cmd_stmt.split(";") for cmd in cmds: trimmed_cmd = cmd.strip() if trimmed_cmd: DB.exec_query(trimmed_cmd) return DB return MockDb()
import sqlalchemy from sqlalchemy.ext.automap import automap_base from sqlalchemy.orm import Session from sqlalchemy import create_engine, inspect, func from sqlalchemy import select, distinct from sqlalchemy import exc from src.db import Db from src.properties_estancia import PropertiesEstancia from src.log import log from src.customException import BadRequest from datetime import datetime, timedelta db = Db() queries = PropertiesEstancia() def query_estancia(fecha_menor, fecha_mayor): engine = db.create_session() consulta = engine.execute( sqlalchemy.text(queries.QUERY_ESTANCIA.format(fecha_menor, fecha_mayor))) lista_diccionario = [] for c in consulta: lista_diccionario.append(c) log.info("Consulta Dao Distribucion Demanda") return lista_diccionario
def db(cls) -> Db: return Db()
def test_instanciation(self): table = mock.Mock(spec=Table) db = Db([table])
from src.field import Field from src.table import Table from src.db import Db fields = [ Field('id', 'int', primary_key=True), Field('name', 'str'), Field('city', 'str', nullable=True), Field('activated', 'bool') ] table = Table('users', fields) db = Db([table]) print(Db)
def __init__(self): self.db = Db() self.file_manager = FileMan('')