Exemple #1
0
 def test_config_object_every_keyword_argument(self):
     """Test that passing every keyword argument creates the expected
     configuration object."""
     assert (conf.create_config(authentication_token="SomeAuth",
                                hostname="SomeHost",
                                use_ssl=False,
                                port=56) == OTHER_EXPECTED_CONFIG)
Exemple #2
0
    def test_empty_config_object(self):
        """Test that an empty configuration object can be created."""
        config = conf.create_config(authentication_token="",
                                    hostname="",
                                    use_ssl="",
                                    port="")

        assert all(value == "" for value in config["api"].values())
Exemple #3
0
    def test_all_environment_variables_defined(self, monkeypatch):
        """Tests that the configuration object is updated correctly when all
        the environment variables are defined."""

        with monkeypatch.context() as m:
            for env_var, value in value_mapping:
                m.setenv(env_var, value)

            config = conf.create_config()
            for v, parsed_value in zip(config["api"].values(),
                                       parsed_values_mapping.values()):
                assert v != parsed_value

            conf.update_from_environment_variables(config)
            for v, parsed_value in zip(config["api"].values(),
                                       parsed_values_mapping.values()):
                assert v == parsed_value
def configuration_wizard():
    r"""Provides an interactive selection wizard on the command line to
    configure every option for the API connection.

    Default configuration options are provided as defaults to the user.
    Configuration options are detailed in :doc:`/code/sf_configuration`.

    Returns:
        dict[str, Union[str, bool, int]]: the configuration options
    """
    default_config = create_config()["api"]

    # Getting default values that can be used for as messages when getting inputs
    hostname_default = default_config["hostname"]
    ssl_default = "y" if default_config["use_ssl"] else "n"
    port_default = default_config["port"]

    authentication_token = input(
        "Please enter the authentication token to use when connecting: [] ")

    if not authentication_token:
        sys.stdout.write(
            "No authentication token was provided, please configure again.")
        sys.exit()

    hostname = (input(
        "Please enter the hostname of the server to connect to: [{}] ".format(
            hostname_default)) or hostname_default)

    ssl_input = (input("Should the client attempt to connect over SSL? [{}] ".
                       format(ssl_default)) or ssl_default)
    use_ssl = ssl_input.upper() == "Y"

    port = (input("Please enter the port number to connect with: [{}] ".format(
        port_default)) or port_default)

    kwargs = {
        "authentication_token": authentication_token,
        "hostname": hostname,
        "use_ssl": use_ssl,
        "port": port,
    }
    return kwargs
Exemple #5
0
    def test_one_environment_variable_defined(self, env_var, key, value,
                                              monkeypatch):
        """Tests that the configuration object is updated correctly when only
        one environment variable is defined."""

        with monkeypatch.context() as m:
            m.setenv(env_var, value)

            config = conf.create_config()
            for v, parsed_value in zip(config["api"].values(),
                                       parsed_values_mapping.values()):
                assert v != parsed_value

            conf.update_from_environment_variables(config)
            assert config["api"][key] == parsed_values_mapping[env_var]

            for v, (key, parsed_value) in zip(config["api"].values(),
                                              parsed_values_mapping.items()):
                if key != env_var:
                    assert v != parsed_value
Exemple #6
0
 def test_config_object_with_authentication_token(self):
     """Test that passing only the authentication token creates the expected
     configuration object."""
     assert (conf.create_config(
         authentication_token="071cdcce-9241-4965-93af-4a4dbc739135") ==
             EXPECTED_CONFIG)