remove first run prompt - fix tests
remove first run prompt, default to generate certs fix tests
This commit is contained in:
parent
d5db3b696c
commit
6b2ed31c9e
3 changed files with 20 additions and 42 deletions
|
|
@ -982,6 +982,7 @@ def create_certs():
|
||||||
subprocess.run([os.path.join("..", "create_certs", "create_certs_linux")])
|
subprocess.run([os.path.join("..", "create_certs", "create_certs_linux")])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
os.chdir(odir)
|
||||||
logging.log(
|
logging.log(
|
||||||
logging.FATAL,
|
logging.FATAL,
|
||||||
"Can't determine platform. Create certs manually and try again.",
|
"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
|
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():
|
def first_run():
|
||||||
yes = {"yes", "y", "ye", ""}
|
|
||||||
print("")
|
|
||||||
if firstrun_input() in yes:
|
|
||||||
create_certs()
|
create_certs()
|
||||||
|
|
||||||
else:
|
|
||||||
logging.log(
|
|
||||||
logging.FATAL,
|
|
||||||
"Can't continue without certificates, please create some then try again.",
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
import argparse
|
import argparse
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ async def test_start_stop():
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
l.check_present(("bumper", "INFO", "Starting Bumper"))
|
||||||
l.clear()
|
l.clear()
|
||||||
assert b.shutting_down == False
|
|
||||||
asyncio.create_task(b.shutdown())
|
asyncio.create_task(b.shutdown())
|
||||||
await asyncio.sleep(0.1)
|
await asyncio.sleep(0.1)
|
||||||
l.check_present(
|
l.check_present(
|
||||||
|
|
|
||||||
|
|
@ -13,29 +13,10 @@ from testfixtures import LogCapture
|
||||||
import sys
|
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):
|
def mock_subrun(*args):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
@patch("bumper.start")
|
@patch("bumper.start")
|
||||||
def test_argparse(mock_start):
|
def test_argparse(mock_start):
|
||||||
bumper.ca_cert = "tests/test_certs/ca.crt"
|
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"
|
platform.system.return_value = "darwin"
|
||||||
bumper.create_certs()
|
bumper.create_certs()
|
||||||
assert mock_run.called == True
|
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"
|
platform.system.return_value = "windows"
|
||||||
bumper.create_certs()
|
bumper.create_certs()
|
||||||
assert mock_run.called == True
|
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"
|
platform.system.return_value = "linux"
|
||||||
bumper.create_certs()
|
bumper.create_certs()
|
||||||
assert mock_run.called == True
|
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.system.return_value = "linux"
|
||||||
platform.machine.return_value = "arm"
|
platform.machine.return_value = "arm"
|
||||||
bumper.create_certs()
|
bumper.create_certs()
|
||||||
assert mock_run.called == True
|
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:
|
with LogCapture() as l:
|
||||||
platform.system.return_value = "nixbad"
|
platform.system.return_value = "nixbad"
|
||||||
|
|
@ -101,7 +94,6 @@ def test_createcert(mock_run, mock_platform, mock_machine, mock_exec):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@patch("bumper.first_run")
|
@patch("bumper.first_run")
|
||||||
def test_main(mock_firstrun):
|
def test_main(mock_firstrun):
|
||||||
bumper.ca_cert = "sf"
|
bumper.ca_cert = "sf"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue