[cli] added the "config" command to the CLI, updated tests
This commit is contained in:
parent
8d2be99068
commit
ed54127c81
|
@ -9,10 +9,12 @@ from halfapi.conf import IS_PROJECT
|
||||||
def cli(ctx, version):
|
def cli(ctx, version):
|
||||||
if version:
|
if version:
|
||||||
import halfapi
|
import halfapi
|
||||||
return click.echo(halfapi.version)
|
return click.echo(halfapi.version())
|
||||||
|
|
||||||
if IS_PROJECT:
|
if IS_PROJECT:
|
||||||
|
import halfapi.cli.config
|
||||||
import halfapi.cli.domain
|
import halfapi.cli.domain
|
||||||
import halfapi.cli.run
|
import halfapi.cli.run
|
||||||
|
|
||||||
else:
|
else:
|
||||||
import halfapi.cli.init
|
import halfapi.cli.init
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
import click
|
||||||
|
|
||||||
|
from .cli import cli
|
||||||
|
from halfapi.conf import (
|
||||||
|
PROJECT_NAME,
|
||||||
|
DOMAINS,
|
||||||
|
CONF_DIR,
|
||||||
|
HOST,
|
||||||
|
PORT,
|
||||||
|
DB_NAME,
|
||||||
|
PRODUCTION,
|
||||||
|
BASE_DIR
|
||||||
|
)
|
||||||
|
|
||||||
|
CONF_STR=f"""
|
||||||
|
[project]
|
||||||
|
name = {PROJECT_NAME}
|
||||||
|
host = {HOST}
|
||||||
|
port = {PORT}
|
||||||
|
production = {PRODUCTION}
|
||||||
|
base_dir = {BASE_DIR}
|
||||||
|
|
||||||
|
[domains]"""
|
||||||
|
|
||||||
|
for dom in DOMAINS:
|
||||||
|
CONF_STR = '\n'.join((CONF_STR, dom))
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def config():
|
||||||
|
"""
|
||||||
|
Lists config parameters and their values
|
||||||
|
"""
|
||||||
|
click.echo(CONF_STR)
|
|
@ -18,8 +18,8 @@ logger = logging.getLogger('halfapi')
|
||||||
#################
|
#################
|
||||||
# domain create #
|
# domain create #
|
||||||
#################
|
#################
|
||||||
def create_domain(name):
|
def create_domain():
|
||||||
pass
|
sys.exit(0)
|
||||||
|
|
||||||
###############
|
###############
|
||||||
# domain read #
|
# domain read #
|
||||||
|
|
|
@ -27,7 +27,9 @@ if IS_PROJECT:
|
||||||
if len(PROJECT_NAME) == 0:
|
if len(PROJECT_NAME) == 0:
|
||||||
raise Exception('Need a project name as argument')
|
raise Exception('Need a project name as argument')
|
||||||
|
|
||||||
DOMAINS = [domain for domain, _ in config.items('domains')]
|
DOMAINS = [domain for domain, _ in config.items('domains')] \
|
||||||
|
if config.has_section('domains') \
|
||||||
|
else []
|
||||||
|
|
||||||
CONF_DIR = environ.get('HALFAPI_CONF_DIR', '/etc/half_api')
|
CONF_DIR = environ.get('HALFAPI_CONF_DIR', '/etc/half_api')
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ if IS_PROJECT:
|
||||||
print('There is no file like {}'.format(config.get('project', 'secret')))
|
print('There is no file like {}'.format(config.get('project', 'secret')))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
PRODUCTION = config.getboolean('project', 'production')
|
PRODUCTION = config.getboolean('project', 'production') or False
|
||||||
os.environ['HALFAPI_PROD'] = str(PRODUCTION)
|
os.environ['HALFAPI_PROD'] = str(PRODUCTION)
|
||||||
|
|
||||||
BASE_DIR = config.get('project', 'base_dir')
|
BASE_DIR = config.get('project', 'base_dir')
|
||||||
|
|
|
@ -24,42 +24,21 @@ class TestCliProj():
|
||||||
assert subproc('halfapi run --help') == 0
|
assert subproc('halfapi run --help') == 0
|
||||||
assert subproc('halfapi domain --help') == 0
|
assert subproc('halfapi domain --help') == 0
|
||||||
|
|
||||||
@pytest.mark.skip
|
def test_config_commands(self, subproc):
|
||||||
def test_domain_commands(self, project_runner):
|
res = subproc('halfapi config pr00t')
|
||||||
res = project_runner(['domain', 'foobar'])
|
assert res == 2
|
||||||
assert res.exit_code == 2
|
res = subproc('halfapi config --help')
|
||||||
res = project_runner(['domain', '--help'])
|
assert res == 0
|
||||||
assert res.exit_code == 0
|
res = subproc('halfapi config')
|
||||||
res = project_runner(['domain', 'create', '--help'])
|
assert res == 0
|
||||||
assert res.exit_code == 0
|
|
||||||
res = project_runner(['domain', 'read', '--help'])
|
|
||||||
assert res.exit_code == 0
|
|
||||||
res = project_runner(['domain', 'update', '--help'])
|
|
||||||
assert res.exit_code == 0
|
|
||||||
res = project_runner(['domain', 'delete', '--help'])
|
|
||||||
assert res.exit_code == 0
|
|
||||||
|
|
||||||
@pytest.mark.skip
|
def test_domain_commands(self, subproc):
|
||||||
def test_domain_create(self, project_runner):
|
res = subproc('halfapi domain foobar')
|
||||||
|
assert res == 2
|
||||||
|
res = subproc('halfapi domain --help')
|
||||||
|
assert res == 0
|
||||||
|
|
||||||
|
def test_domain_create(self, subproc):
|
||||||
DOMNAME='tmp_domain'
|
DOMNAME='tmp_domain'
|
||||||
res = project_runner(['domain', 'create', DOMNAME])
|
res = subproc(f'halfapi domain --create')
|
||||||
srcdir = os.path.join('domains', 'src', DOMNAME)
|
assert res == 0
|
||||||
assert os.path.isdir(srcdir)
|
|
||||||
moddir = os.path.join(srcdir, DOMNAME)
|
|
||||||
assert os.path.isdir(moddir)
|
|
||||||
setup = os.path.join(srcdir, 'setup.py')
|
|
||||||
assert os.path.isfile(setup)
|
|
||||||
initfile = os.path.join(moddir, '__init__.py')
|
|
||||||
assert os.path.isfile(initfile)
|
|
||||||
aclfile = os.path.join(moddir, 'acl.py')
|
|
||||||
assert os.path.isfile(aclfile)
|
|
||||||
aclsdir = os.path.join(moddir, 'acls')
|
|
||||||
assert os.path.isdir(aclsdir)
|
|
||||||
routersdir = os.path.join(moddir, 'routers')
|
|
||||||
assert os.path.isdir(routersdir)
|
|
||||||
|
|
||||||
try:
|
|
||||||
dom_mod = importlib.import_module(DOMNAME, srcdir)
|
|
||||||
assert hasattr(dom_mod, 'ROUTERS')
|
|
||||||
except ImportError:
|
|
||||||
assert False
|
|
||||||
|
|
Loading…
Reference in New Issue