[tests] updated tests for init-project
This commit is contained in:
parent
a3c3d7c816
commit
74c2c4e056
|
@ -4,6 +4,7 @@ import os
|
||||||
import pytest
|
import pytest
|
||||||
from click.testing import CliRunner
|
from click.testing import CliRunner
|
||||||
|
|
||||||
|
from halfapi import __version__
|
||||||
from halfapi.cli import cli
|
from halfapi.cli import cli
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
@ -12,6 +13,7 @@ def runner():
|
||||||
|
|
||||||
def test_init_project(runner):
|
def test_init_project(runner):
|
||||||
# Missing argument (project)
|
# Missing argument (project)
|
||||||
|
testproject = 'testproject'
|
||||||
r = runner.invoke(cli, ['init-project'])
|
r = runner.invoke(cli, ['init-project'])
|
||||||
assert r.exit_code == 2
|
assert r.exit_code == 2
|
||||||
|
|
||||||
|
@ -22,22 +24,34 @@ def test_init_project(runner):
|
||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
# Fail : Already existing folder
|
# Fail : Already existing folder
|
||||||
os.mkdir('testproject')
|
os.mkdir(testproject)
|
||||||
r = runner.invoke(cli, ['init-project', 'testproject'])
|
r = runner.invoke(cli, ['init-project', testproject])
|
||||||
assert r.exit_code == 1
|
assert r.exit_code == 1
|
||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
# Fail : Already existing nod
|
# Fail : Already existing nod
|
||||||
os.mknod('testproject')
|
os.mknod(testproject)
|
||||||
r = runner.invoke(cli, ['init-project', 'testproject'])
|
r = runner.invoke(cli, ['init-project', testproject])
|
||||||
assert r.exit_code == 1
|
assert r.exit_code == 1
|
||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
# Success : New repo
|
# Success : New repo
|
||||||
r = runner.invoke(cli, ['init-project', 'testproject'])
|
r = runner.invoke(cli, ['init-project', testproject])
|
||||||
assert r.exit_code == 0
|
assert r.exit_code == 0
|
||||||
assert os.path.isdir('testproject')
|
assert os.path.isdir(testproject)
|
||||||
assert os.path.isdir('testproject/.git')
|
assert os.path.isdir(f'{testproject}/.git')
|
||||||
|
assert os.path.isdir(f'{testproject}/.halfapi')
|
||||||
|
domain_file = 'testproject/.halfapi/domain'
|
||||||
|
assert os.path.isfile(domain_file)
|
||||||
|
conf_file = 'testproject/.halfapi/config'
|
||||||
|
assert os.path.isfile(conf_file)
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read([conf_file])
|
||||||
|
assert config.has_section('project')
|
||||||
|
assert config.has_option('project', 'name')
|
||||||
|
assert config.get('project', 'name') == testproject
|
||||||
|
assert config.has_option('project', 'halfapi_version') == __version__
|
||||||
|
|
||||||
|
|
||||||
with runner.isolated_filesystem():
|
with runner.isolated_filesystem():
|
||||||
# Success : Cloned repo
|
# Success : Cloned repo
|
||||||
|
@ -45,7 +59,9 @@ def test_init_project(runner):
|
||||||
pygit2.init_repository('testproject.git', bare=True)
|
pygit2.init_repository('testproject.git', bare=True)
|
||||||
assert os.path.isdir('testproject.git')
|
assert os.path.isdir('testproject.git')
|
||||||
|
|
||||||
r = runner.invoke(cli, ['init-project', 'testproject', '--repo', './testproject.git'])
|
r = runner.invoke(cli, [
|
||||||
|
'init-project', testproject, '--repo',
|
||||||
|
f'./{testproject}.git'])
|
||||||
assert r.exit_code == 0
|
assert r.exit_code == 0
|
||||||
assert os.path.isdir('testproject')
|
assert os.path.isdir(testproject)
|
||||||
assert os.path.isdir('testproject/.git')
|
assert os.path.isdir('testproject/.git')
|
||||||
|
|
Loading…
Reference in New Issue