CommandOptions   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 2
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 2
rs 10
wmc 0
1
"""
2
helpers to get the configuration files right
3
"""
4
import os
5
6
from alembic.config import Config
7
from paste.deploy.loadwsgi import appconfig
8
9
10
def get_config_file_path():
11
    test_dir = os.path.dirname(__file__)
12
    private_file = os.path.join(test_dir, 'test-private.ini')
13
    if os.path.isfile(private_file):
14
        return os.path.join(test_dir, private_file)
15
16
    return os.path.join(test_dir, 'test.ini')
17
18
19
def get_config():
20
    test_dir = os.path.dirname(__file__)
21
    private_file = os.path.join(test_dir, 'test-private.ini')
22
    if os.path.isfile(private_file):
23
        return appconfig('config:' + os.path.join(test_dir, private_file))
24
25
    return appconfig('config:' + os.path.join(test_dir, 'test.ini'))
26
27
28
def get_alembic_config():
29
    if os.path.exists("alembic.ini"):
30
        alembic_config = Config("alembic.ini")  # run from <project root>
31
    else:
32
        alembic_config = Config("../alembic.ini")  # run from <project root>/tests folder
33
        alembic_config.set_main_option("script_location", "../alembic")
34
    alembic_config.set_main_option("sqlalchemy.url", get_config()['sqlalchemy.url'])
35
36
    class CommandOptions(object):
37
        x = ["context=py_test"]  # doesn't run production stuff like grants
38
    alembic_config.cmd_opts = CommandOptions()
39
    return alembic_config
40