示例#1
0
import os
from src.config import config
from src.scripts import configure_logging

config.load_config(os.path.dirname(__file__) + "/../src/config/test.json")
configure_logging.configure_logging()
示例#2
0
 def setUpClass(cls):
     # Make sure that the database is clean before this class is run.
     cls.old_config = config.CONFIG
     config.load_config(os.path.dirname(__file__) + "/../../src/config/staging.json")
     configure_logging.configure_logging()
     load_data.load_data()
示例#3
0
"""
db.py: Manage DB Connection
Copyright 2017-2018 LinhHo Training.
"""

from contextlib import contextmanager
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
from src.config import config

config_data = config.load_config()
sql_config = config_data['sql']
url = '{}://{}:{}@{}:{}/{}'

# url = url.format(sql_config['type'], sql_config['username'],
#                  sql_config['password'], sql_config['host'],
#                  sql_config['port'], sql_config['database'])
# url = "postgresql+psycopg2://postgres:[email protected]:5432/training"
url = 'mysql+pymysql://root:[email protected]:3306/linh_clone'
engine = create_engine(url)
# engine = None

Base = declarative_base()
_session = scoped_session(sessionmaker(bind=engine, autoflush=True))
# _session = None

# def create_engine(_url):
#     """
#     Init database engine connection
#     :param connection_string:
示例#4
0
 def test_load_prod(self):
     """ Verifies that the prod.json config file is properly loaded."""
     config.load_config(ConfigTest.CONFIG_PATH + "prod.json")
     with open(ConfigTest.CONFIG_PATH + "prod.json", "r") as config_file:
         self.assertEqual(config.CONFIG, json.load(config_file))