[tests][cli] added tests for domain command

This commit is contained in:
Maxime Alves LIRMM 2020-08-05 12:27:56 +02:00
parent 048d06de37
commit 7ff8d803ee
1 changed files with 43 additions and 7 deletions

View File

@ -25,10 +25,16 @@ def dropdb():
p = subprocess.Popen(['dropdb', f'halfapi_{PROJNAME}'])
p.wait()
@pytest.fixture
def createdb():
p = subprocess.Popen(['createdb', f'halfapi_{PROJNAME}'])
p.wait()
return
@pytest.mark.incremental
class TestCli():
def test_options(self, runner, dropdb):
def test_options(self, runner, dropdb, createdb):
# Wrong command
with runner.isolated_filesystem():
r = runner.invoke(cli, ['foobar'])
@ -44,7 +50,7 @@ class TestCli():
assert r.exit_code == 0
with runner.isolated_filesystem():
r = runner.invoke(cli, ['init-project', '--help'])
r = runner.invoke(cli, ['init', '--help'])
assert r.exit_code == 0
with runner.isolated_filesystem():
@ -59,24 +65,24 @@ class TestCli():
def test_init_project_fail(self, runner, dropdb):
# Missing argument (project)
testproject = 'testproject'
r = runner.invoke(cli, ['init-project'])
r = runner.invoke(cli, ['init'])
assert r.exit_code == 2
with runner.isolated_filesystem():
# Fail : Wrong project name
r = runner.invoke(cli, ['init-project', 'test*-project'])
r = runner.invoke(cli, ['init', 'test*-project'])
assert r.exit_code == 1
with runner.isolated_filesystem():
# Fail : Already existing folder
os.mkdir(testproject)
r = runner.invoke(cli, ['init-project', testproject])
r = runner.invoke(cli, ['init', testproject])
assert r.exit_code == 1
with runner.isolated_filesystem():
# Fail : Already existing nod
os.mknod(testproject)
r = runner.invoke(cli, ['init-project', testproject])
r = runner.invoke(cli, ['init', testproject])
assert r.exit_code == 1
def test_init_project(self, runner, dropdb):
@ -87,7 +93,7 @@ class TestCli():
'HALFAPI_CONF_DIR': os.environ.get('HALFAPI_CONF_DIR', os.getcwd()),
}
res = runner.invoke(cli, ['init-project', PROJNAME], env=env)
res = runner.invoke(cli, ['init', PROJNAME], env=env)
try:
assert os.path.isdir(PROJNAME)
assert os.path.isdir(os.path.join(PROJNAME, '.halfapi'))
@ -132,3 +138,33 @@ class TestCli():
with runner.isolated_filesystem():
res = runner.invoke(cli, ['domain', 'delete', '--help'])
assert r.exit_code == 0
def test_domain_create(self, runner, dropdb):
with runner.isolated_filesystem():
res = runner.invoke(cli, ['init', PROJNAME])
assert res.exit_code == 0
os.chdir(PROJNAME)
DOMNAME='tmp_domain'
res = runner.invoke(cli, ['domain', 'create', DOMNAME])
srcdir = os.path.join('domains', 'src', DOMNAME)
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