def test_deploy_ctl_wrapper(m_utils, m_sh): m_utils.user_home_exists.return_value = True actions.deploy_ctl_wrapper() m_sh.assert_called_with(matching('mkdir -p')) m_utils.user_home_exists.return_value = False actions.deploy_ctl_wrapper() m_sh.assert_called_with(matching('sudo cp'))
def test_disable_ssh_accept_env(m_utils, m_sh, mocker): m_file = mocker.patch(TESTED + '.Path').return_value lines = '\n'.join([ '# Allow client to pass locale environment variables', 'AcceptEnv LANG LC_*' ]) comment_lines = '\n'.join([ '# Allow client to pass locale environment variables', '#AcceptEnv LANG LC_*' ]) # File not exists m_file.exists.return_value = False actions.disable_ssh_accept_env() assert m_sh.call_count == 0 # No change m_file.exists.return_value = True m_file.read_text.return_value = comment_lines actions.disable_ssh_accept_env() assert m_sh.call_count == 0 # Changed, but no sevice restart m_file.read_text.return_value = lines m_utils.command_exists.return_value = False actions.disable_ssh_accept_env() m_sh.assert_called_with(matching('sudo cp')) # Changed, full change m_file.read_text.return_value = lines m_utils.command_exists.return_value = True actions.disable_ssh_accept_env() m_sh.assert_called_with(matching('sudo systemctl restart'))
def test_save_backup(mocker, m_utils, f_save_backup): m_mkdir = mocker.patch(TESTED + '.mkdir') m_zipfile = mocker.patch(TESTED + '.zipfile.ZipFile') invoke(backup.save) m_mkdir.assert_called_once_with(path.abspath('backup/')) m_zipfile.assert_called_once_with( matching(r'^backup/brewblox_backup_\d{8}_\d{4}.zip'), 'w', zipfile.ZIP_DEFLATED) m_zipfile.return_value.write.assert_called_with('docker-compose.yml') assert m_zipfile.return_value.writestr.call_args_list == [ call('brewblox-ui-store.datastore.json', json.dumps([{ 'id': 1 }, { 'id': 2 }, { 'id': 3 }])), call('brewblox-automation.datastore.json', json.dumps([{ 'id': 4 }, { 'id': 5 }, { 'id': 6 }])), call('spark-one.spark.json', 'resp_text'), ]
def test_matching(): obj = testing.matching(r'.art') assert obj == 'cart' assert obj == 'part' mock = Mock() mock('fart') mock.assert_called_with(obj)
def test_install_existing_continue(m_utils, m_sh): m_utils.path_exists.return_value = True m_utils.confirm.side_effect = [ True, # ok using dir True, # continue existing dir False, # prompt reboot ] m_utils.is_docker_user.return_value = True m_utils.command_exists.side_effect = [ False, # apt True, # docker ] invoke(install.install, '--no-use-defaults') m_utils.confirm.assert_any_call(matching(r'.*brewblox already exists.*')) assert m_sh.call_count == 3 m_sh.assert_called_with('sudo reboot')
def test_save_backup(mocker, m_utils, f_read_compose): set_responses() m_mkdir = mocker.patch(TESTED + '.mkdir') m_zipfile = mocker.patch(TESTED + '.zipfile.ZipFile') invoke(backup.save) m_mkdir.assert_called_once_with(Path('backup/').resolve()) m_zipfile.assert_called_once_with( matching(r'^backup/brewblox_backup_\d{8}_\d{4}.zip'), 'w', zipfile.ZIP_DEFLATED) m_zipfile.return_value.write.assert_any_call('docker-compose.yml') assert m_zipfile.return_value.writestr.call_args_list == [ call('global.redis.json', json.dumps(redis_data())), call('spark-one.spark.json', json.dumps(blocks_data())), ] # wait, get datastore, get spark assert len(httpretty.latest_requests()) == 3
def test_list_devices(m_utils, m_browser, m_conf, m_usb, mocker): m_echo = mocker.patch(discovery.tabular.__name__ + '.click.echo') discovery.list_devices('all') assert m_echo.call_count == 6 # headers, spacers, 2 lan, 2 usb m_echo.assert_called_with(matching('LAN Spark 4 id2'))
def test_load_defaults(m_actions, m_utils, m_sh): m_utils.path_exists.return_value = False invoke(snapshot.load) cwd = Path('.').resolve().name + '/' m_sh.assert_called_with(matching(r'.*' + cwd))
def test_save_defaults(m_utils, m_sh): m_utils.path_exists.return_value = False invoke(snapshot.save) cwd = Path('.').resolve().name m_sh.assert_called_with(matching(r'sudo tar -C .* -czf ../brewblox.tar.gz ' + cwd))
def test_save(m_utils, m_sh): m_utils.path_exists.return_value = False invoke(snapshot.save) m_sh.assert_any_call(matching(r'sudo tar -C .* -czf'))
def test_discover_device(m_utils, m_sh): m_utils.docker_tag.return_value = 'taggy' assert spark.discover_device('wifi', None) == [] m_sh.assert_called_with( matching(r'.* brewblox/brewblox-mdns:taggy --cli --discovery wifi'), capture=True)