Beispiel #1
0
def test_create_droplet_decline_droplet_data(m_create_manager,
                                             m_confirm_account, m_questions,
                                             capsys):
    manager = mock.Mock()
    m_create_manager.return_value = manager
    m_confirm_account.return_value = True
    m_questions.ask_for_image_type.return_value = "all"
    m_questions.ask_for_image.return_value = (
        Image(name="ubuntu 18", slug="ubuntu-18"),
        ["ams1", "nyc1", "ams2"],
    )
    m_questions.ask_for_region.return_value = (
        Region(name="Amsterdam 1", slug="ams-1"),
        ["1gb", "2gb", "5gb"],
    )
    m_questions.ask_for_size.return_value = Size(name="1 GB", slug="1gb")
    m_questions.ask_for_droplet_name.return_value = "droplet_name"
    m_questions.confirm_ssh_addition.return_value = False
    m_questions.confirm_backups_addition.return_value = False
    m_questions.confirm_ipv6_addition.return_value = False
    m_questions.confirm_tags_addition.return_value = False
    m_questions.confirm_droplet_data.return_value = False
    res = create_droplet("token")
    captured = capsys.readouterr()
    assert "Configuration declined!" in captured.out
    assert res is None
Beispiel #2
0
def create_the_droplet(token):
    """
    Creates a DigitalOcean droplet and after finishing, returns
    a JSON response with the droplet's data.

    :param str token: the Digital Ocean API token
    :return: a json response
    """
    return create_droplet(token=token)
Beispiel #3
0
def test_create_droplet_scenario_3(m_create_manager, m_confirm_account,
                                   m_questions, m_helpers):
    manager = mock.Mock()
    m_create_manager.return_value = manager
    m_confirm_account.return_value = True
    m_questions.ask_for_image_type.return_value = "all"
    m_questions.ask_for_image.return_value = (
        Image(name="ubuntu 18", slug="ubuntu-18"),
        ["ams1", "nyc1", "ams2"],
    )
    m_questions.ask_for_region.return_value = (
        Region(name="Amsterdam 1", slug="ams-1"),
        ["1gb", "2gb", "5gb"],
    )
    m_questions.ask_for_size.return_value = Size(name="1 GB", slug="1gb")
    m_questions.ask_for_droplet_name.return_value = "droplet_name"
    m_questions.confirm_ssh_addition.return_value = True
    m_questions.ask_for_ssh_keys_addition_method.return_value = "local"
    m_helpers.handle_ssh_keys.return_value = ["ssh_fingerprint1"]
    m_questions.confirm_backups_addition.return_value = False
    m_questions.confirm_ipv6_addition.return_value = False
    m_questions.confirm_tags_addition.return_value = True
    m_questions.ask_for_tag_addition_method.return_value = "remote"
    m_helpers.handle_tags.return_value = ["tag1", "tag2"]
    m_questions.confirm_droplet_data.return_value = True

    droplet_params = {
        "token": manager.token,
        "name": "droplet_name",
        "size_slug": "1gb",
        "image": "ubuntu-18",
        "region": "ams-1",
        "ssh_keys": ["ssh_fingerprint1"],
        "backups": False,
        "ipv6": False,
        "tags": ["tag1", "tag2"],
    }
    create_droplet("token")
    m_helpers.handle_tags.assert_called_once_with(manager, "remote")
    m_helpers.create_droplet_now.assert_called_once_with(droplet_params)
    assert m_helpers.droplet_data_json.call_count == 1
Beispiel #4
0
def test_create_droplet_decline_account(m_create_manager, m_confirm_account,
                                        capsys):
    manager = mock.Mock()
    err = "Please run the script with the preferred API token. " \
          "Thanks for using this tool! ♥"
    m_create_manager.return_value = manager
    m_confirm_account.return_value = False
    with pytest.raises(SystemExit) as sys_call:
        res = create_droplet("token")
        captured = capsys.readouterr()
        assert res is None
        assert err in captured.out
    m_create_manager.assert_called_once_with("token")
    assert sys_call.type == SystemExit
    assert sys_call.value.code == 0
Beispiel #5
0
def create_droplet_click(token):
    """
    Creates a droplet in your DigitalOcean account.

    Accepts one option (the Digital Ocean API token key).

    token: [env var name | path to file | token str] Resolved in that order.
    Example:

    droplet -t MY_TOKEN

    The above will first look at an environment variable named MY_TOKEN.
    Fail that, it'll look at a file named MY_TOKEN.
    Fail that, it'll use the str "MY_TOKEN" as the Digital Ocean API
    token (which will fail, obviously).
    If option omitted then it will look at DO_TOKEN env var.
    """
    res = create_droplet(token=token)
    if res:
        click.echo(res)
    return 0