Exemple #1
0
def main(ctx, config_file, config_pairs, debug, mock_requests):
    """Buy and sell anything on the internet for bitcoin.

\b
For detailed help, run 21 help --detail.
For full documentation, visit 21.co/learn.
"""
    need_wallet_and_account = ctx.invoked_subcommand not in (
        'help', 'update', 'login', 'doctor', 'uninstall')

    # Set UUID if available
    uuid = bitcoin_computer.get_device_uuid()
    if uuid:
        two1.TWO1_DEVICE_ID = uuid

    try:
        ctx.obj = parse_config(
            config_file=config_file,
            config_dict=dict(config_pairs),
            need_wallet_and_account=need_wallet_and_account,
            debug=debug,
        )
    except requests.ConnectionError:
        # If a user is not connected to the internet, this should be
        # the first place we encounter an error
        logger.error(
            'A connection error has occurred. Please check your internet connection',
            fg='red')
        if debug:
            raise
        else:
            sys.exit(1)
Exemple #2
0
def _doctor(two1_config):

    # warm welcome message
    logger.info(uxstring.UxString.doctor_start)

    # Get an appointment with the doctor
    doc = Doctor(two1_config)

    # Get a general doctor checkup
    doc.checkup("general")
    doc.checkup("dependency")
    doc.checkup("server")
    if bitcoin_computer.get_device_uuid():
        doc.checkup("BC")

    logger.info("\n" + uxstring.UxString.doctor_total)

    # groups all checks into one class for reuse of print_summary
    doc.print_results()

    if len(doc.get_checks(Check.Result.FAIL)) == 0:
        return doc.to_dict()
    else:
        raise exceptions.Two1Error("21 doctor failed some checks.",
                                   json=doc.to_dict())
Exemple #3
0
def main(ctx, config_file, config_pairs, debug, mock_requests):
    """Buy and sell anything on the internet for bitcoin.

\b
For detailed help, run 21 help --detail.
For full documentation, visit 21.co/learn.
"""
    need_wallet_and_account = ctx.invoked_subcommand not in ('help', 'update',
                                                             'login', 'doctor',
                                                             'uninstall')
    check_update = ctx.invoked_subcommand not in ('update')

    # Set UUID if available
    uuid = bitcoin_computer.get_device_uuid()
    if uuid:
        two1.TWO1_DEVICE_ID = uuid

    try:
        ctx.obj = parse_config(
            config_file=config_file,
            config_dict=dict(config_pairs),
            need_wallet_and_account=need_wallet_and_account,
            check_update=check_update,
            debug=debug,
        )
    except requests.ConnectionError:
        # If a user is not connected to the internet, this should be
        # the first place we encounter an error
        logger.error(
            'A connection error has occurred. Please check your internet connection',
            fg='red')
        if debug:
            raise
        else:
            sys.exit(1)
Exemple #4
0
def initialize_client():
    uuid = bitcoin_computer.get_device_uuid()
    if uuid:
        two1.TWO1_DEVICE_ID = uuid
    try:
        config = two1_config.Config(two1.TWO1_CONFIG_FILE, dict())
        ctx = dict()
    except exceptions.FileDecodeError as e:
        raise click.ClickException(uxstring.UxString.Error.file_decode.format((str(e))))
    wallet = wallet_utils.get_or_create_wallet(config.wallet_path)
    machine_auth = machine_auth_wallet.MachineAuthWallet(wallet)
    config.username = account_utils.get_or_create_username(config, machine_auth)
    client = rest_client.TwentyOneRestClient(two1.TWO1_HOST, machine_auth, config.username)
    ctx['client'] = client
    ctx['config'] = config
    ctx['wallet'] = wallet
    return ctx;
Exemple #5
0
def main(ctx, config_file, config_pairs):
    """Buy and sell anything on the internet for bitcoin.

\b
For detailed help, run 21 help --detail.
For full documentation, visit 21.co/learn.
"""
    need_wallet_and_account = ctx.invoked_subcommand not in (
        'help', 'update', 'login', 'doctor')

    # Set UUID if available
    uuid = bitcoin_computer.get_device_uuid()
    if uuid:
        two1.TWO1_DEVICE_ID = uuid

    ctx.obj = parse_config(config_file,
                           dict(config_pairs),
                           need_wallet_and_account=need_wallet_and_account)
Exemple #6
0
def main(ctx, config_file, config_pairs, debug):
    """Buy and sell anything on the internet for bitcoin.

\b
For detailed help, run 21 help --detail.
For full documentation, visit 21.co/learn.
"""
    need_wallet_and_account = ctx.invoked_subcommand not in ('help', 'update',
                                                             'login', 'doctor')

    # Set UUID if available
    uuid = bitcoin_computer.get_device_uuid()
    if uuid:
        two1.TWO1_DEVICE_ID = uuid

    ctx.obj = parse_config(
        config_file=config_file,
        config_dict=dict(config_pairs),
        need_wallet_and_account=need_wallet_and_account,
        debug=debug,
    )
Exemple #7
0
def _doctor(two1_config):

    # warm welcome message
    logger.info(uxstring.UxString.doctor_start)

    # Get an appointment with the doctor
    doc = Doctor(two1_config)

    # Get a general doctor checkup
    doc.checkup("general")
    doc.checkup("dependency")
    doc.checkup("server")
    if bitcoin_computer.get_device_uuid():
        doc.checkup("BC")

    logger.info("\n" + uxstring.UxString.doctor_total)

    # groups all checks into one class for reuse of print_summary
    doc.print_results()

    if len(doc.get_checks(Check.Result.FAIL)) == 0:
        return doc.to_dict()
    else:
        raise exceptions.Two1Error("21 doctor failed some checks.", json=doc.to_dict())
def test_get_uuid(mock_file, side_effect, outcome):
    """ Mocks the builtin open function to test various outcomes of opening and reading the uuid file """
    with mock.patch.object(builtins, "open", mock_file) as open_mock:
        open_mock.side_effect = side_effect
        assert bitcoin_computer.get_device_uuid() == outcome