[tests][cli] init_project tests passes
This commit is contained in:
parent
50314e6656
commit
d47f735828
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
@ -9,19 +10,31 @@ from halfapi.cli import cli
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser
|
||||||
|
|
||||||
projname = os.environ.get('PROJ','tmp_api')
|
projname = os.environ.get('PROJ','tmp_api')
|
||||||
def test_init_project():
|
|
||||||
|
@pytest.fixture
|
||||||
|
def dropdb():
|
||||||
|
p = subprocess.Popen(['dropdb', f'halfapi_{projname}'])
|
||||||
|
p.wait()
|
||||||
|
yield
|
||||||
|
|
||||||
|
p = subprocess.Popen(['dropdb', f'halfapi_{projname}'])
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
def test_init_project(dropdb):
|
||||||
runner = CliRunner()
|
runner = CliRunner()
|
||||||
cp = ConfigParser()
|
cp = ConfigParser()
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
runner.env = {
|
env = {
|
||||||
'HALFORM_CONF_DIR': os.environ.get('HALFORM_CONF_DIR', os.getcwd()),
|
'HALFORM_CONF_DIR': os.environ.get('HALFORM_CONF_DIR', os.getcwd()),
|
||||||
'HALFAPI_CONF_DIR': os.environ.get('HALFAPI_CONF_DIR', os.getcwd()),
|
'HALFAPI_CONF_DIR': os.environ.get('HALFAPI_CONF_DIR', os.getcwd()),
|
||||||
}
|
}
|
||||||
|
|
||||||
res = runner.invoke(cli, ['init-project', projname])
|
res = runner.invoke(cli, ['init-project', projname], env=env)
|
||||||
|
try:
|
||||||
assert os.path.isdir(projname)
|
assert os.path.isdir(projname)
|
||||||
assert os.path.isdir(os.path.join(projname, '.halfapi'))
|
assert os.path.isdir(os.path.join(projname, '.halfapi'))
|
||||||
|
|
||||||
|
|
||||||
# .halfapi/config check
|
# .halfapi/config check
|
||||||
assert os.path.isfile(os.path.join(projname, '.halfapi', 'config'))
|
assert os.path.isfile(os.path.join(projname, '.halfapi', 'config'))
|
||||||
cp.read(os.path.join(projname, '.halfapi', 'config'))
|
cp.read(os.path.join(projname, '.halfapi', 'config'))
|
||||||
|
@ -34,8 +47,10 @@ def test_init_project():
|
||||||
assert os.path.isfile(os.path.join(projname, '.halfapi', 'domains'))
|
assert os.path.isfile(os.path.join(projname, '.halfapi', 'domains'))
|
||||||
cp.read(os.path.join(projname, '.halfapi', 'domains'))
|
cp.read(os.path.join(projname, '.halfapi', 'domains'))
|
||||||
assert cp.has_section('domains')
|
assert cp.has_section('domains')
|
||||||
|
except AssertionError:
|
||||||
|
subprocess.run(['tree', '-a', os.getcwd()])
|
||||||
|
|
||||||
assert r.exit_code == 0
|
assert res.exit_code == 0
|
||||||
assert r.exception is None
|
assert res.exception is None
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue