def _join(client, network): """Join the given network. Args: client (two1.server.rest_client.TwentyOneRestClient) an object for sending authenticated requests to the TwentyOne backend network (str): the name of the network being joined. Defaults to 21market Raises: ServerRequestError: if server returns an error code other than 401 """ try: if zerotier.is_installed(): # ensures the zerotier daemon is running zerotier.start_daemon() else: logger.info(uxstring.UxString.install_zerotier) zt_device_address = zerotier.device_address() response = client.join(network, zt_device_address) if response.ok: network_id = response.json().get("networkid") zerotier.join_network(network_id) logger.info(uxstring.UxString.successful_join.format(click.style(network, fg="magenta"))) except exceptions.ServerRequestError as e: if e.status_code == 400: logger.info(uxstring.UxString.invalid_network) else: raise e except subprocess.CalledProcessError as e: logger.info(str(e))
def test_is_installed(mock_return_value, outcome): """ Simple test to ensure proper values are returned from is_installed """ with mock.patch("two1.commands.util.zerotier.shutil.which", return_value=mock_return_value): assert zerotier.is_installed() == outcome