remove first run prompt - fix tests

remove first run prompt, default to generate certs
fix tests
This commit is contained in:
Brian Martin 2019-06-10 22:10:18 -04:00
parent d5db3b696c
commit 6b2ed31c9e
3 changed files with 20 additions and 42 deletions

View file

@ -982,6 +982,7 @@ def create_certs():
subprocess.run([os.path.join("..", "create_certs", "create_certs_linux")])
else:
os.chdir(odir)
logging.log(
logging.FATAL,
"Can't determine platform. Create certs manually and try again.",
@ -1000,24 +1001,9 @@ def create_certs():
os.execv(sys.executable, ["python"] + sys.argv) # Start again
def firstrun_input():
return input(
"No certificates found, would you like to create them automatically? (y/n): "
).lower()
def first_run():
yes = {"yes", "y", "ye", ""}
print("")
if firstrun_input() in yes:
create_certs()
else:
logging.log(
logging.FATAL,
"Can't continue without certificates, please create some then try again.",
)
def main(argv=None):
import argparse

View file

@ -41,7 +41,7 @@ async def test_start_stop():
await asyncio.sleep(0.1)
l.check_present(("bumper", "INFO", "Starting Bumper"))
l.clear()
assert b.shutting_down == False
asyncio.create_task(b.shutdown())
await asyncio.sleep(0.1)
l.check_present(

View file

@ -13,29 +13,10 @@ from testfixtures import LogCapture
import sys
@patch("bumper.firstrun_input")
@patch("bumper.create_certs")
def test_firstrun(mock_input, mock_create):
with LogCapture() as l:
bumper.firstrun_input.return_value = "n"
bumper.first_run()
l.check_present(
(
"root",
"CRITICAL",
"Can't continue without certificates, please create some then try again.",
)
)
bumper.firstrun_input.return_value = "y"
bumper.first_run()
assert mock_create.called == True
def mock_subrun(*args):
return args
@patch("bumper.start")
def test_argparse(mock_start):
bumper.ca_cert = "tests/test_certs/ca.crt"
@ -70,23 +51,35 @@ def test_createcert(mock_run, mock_platform, mock_machine, mock_exec):
platform.system.return_value = "darwin"
bumper.create_certs()
assert mock_run.called == True
assert os.path.join("..", "create_certs", "create_certs_osx") in mock_exec.call_args.args[0]
assert (
os.path.join("..", "create_certs", "create_certs_osx")
in mock_exec.call_args.args[0]
)
platform.system.return_value = "windows"
bumper.create_certs()
assert mock_run.called == True
assert os.path.join("..", "create_certs", "create_certs_windows.exe") in mock_exec.call_args.args[0]
assert (
os.path.join("..", "create_certs", "create_certs_windows.exe")
in mock_exec.call_args.args[0]
)
platform.system.return_value = "linux"
bumper.create_certs()
assert mock_run.called == True
assert os.path.join("..", "create_certs","create_certs_linux") in mock_exec.call_args.args[0]
assert (
os.path.join("..", "create_certs", "create_certs_linux")
in mock_exec.call_args.args[0]
)
platform.system.return_value = "linux"
platform.machine.return_value = "arm"
bumper.create_certs()
assert mock_run.called == True
assert os.path.join("..", "create_certs", "create_certs_rpi") in mock_exec.call_args.args[0]
assert (
os.path.join("..", "create_certs", "create_certs_rpi")
in mock_exec.call_args.args[0]
)
with LogCapture() as l:
platform.system.return_value = "nixbad"
@ -101,7 +94,6 @@ def test_createcert(mock_run, mock_platform, mock_machine, mock_exec):
)
@patch("bumper.first_run")
def test_main(mock_firstrun):
bumper.ca_cert = "sf"