Esempio n. 1
0
def test_resolve_profile_missing_client_secret(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch(
        "faculty.config.load_profile", return_value=PROFILE_WITHOUT_SECRET
    )
    with pytest.raises(config.CredentialsError, match="client_secret"):
        config.resolve_profile()
Esempio n. 2
0
def test_resolve_profile_profile_name_env_faculty_precendence(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=OTHER_PROFILE)
    mocker.patch.dict(
        os.environ,
        {"FACULTY_PROFILE": "other", "SHERLOCKML_PROFILE": "ignored"},
    )
    config.resolve_profile()
    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "other"
    )
Esempio n. 3
0
def test_resolve_profile_profile_name_env(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=OTHER_PROFILE)
    mocker.patch.dict(os.environ, {"FACULTY_PROFILE": "other"})

    assert config.resolve_profile() == OTHER_PROFILE

    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "other")
Esempio n. 4
0
def test_resolve_profile_profile_name_override(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=OTHER_PROFILE)

    profile = config.resolve_profile(profile_name="other")
    assert profile == OTHER_PROFILE

    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "other")
Esempio n. 5
0
def test_resolve_profile(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=DEFAULT_PROFILE)

    assert config.resolve_profile() == DEFAULT_PROFILE

    config.resolve_credentials_path.assert_called_once_with(None)
    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "default")
Esempio n. 6
0
def test_resolve_profile_overrides(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=DEFAULT_PROFILE)
    profile = config.resolve_profile(
        domain="other.domain.com",
        protocol="other-protocol",
        client_id="other-client-id",
        client_secret="other-client-secret",
    )
    assert profile == OTHER_PROFILE
Esempio n. 7
0
def test_resolve_profile_profile_name_env_sherlockml(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=OTHER_PROFILE)
    mocker.patch.dict(os.environ, {"SHERLOCKML_PROFILE": "other"})

    with pytest.warns(UserWarning, match="SHERLOCKML_PROFILE is deprecated"):
        assert config.resolve_profile() == OTHER_PROFILE

    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "other")
Esempio n. 8
0
def test_resolve_profile_credentials_path_override(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=DEFAULT_PROFILE)

    profile = config.resolve_profile(credentials_path="test/path")
    assert profile == DEFAULT_PROFILE

    config.resolve_credentials_path.assert_called_once_with("test/path")
    config.load_profile.assert_called_once_with(
        config.resolve_credentials_path.return_value, "default")
Esempio n. 9
0
def test_resolve_profile_defaults(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile",
                 return_value=CREDENTIALS_ONLY_PROFILE)
    profile = config.resolve_profile()
    assert profile == config.Profile(
        domain=config.DEFAULT_DOMAIN,
        protocol=config.DEFAULT_PROTOCOL,
        client_id="test-client-id",
        client_secret="test-client-secret",
    )
Esempio n. 10
0
def test_resolve_profile_env(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=DEFAULT_PROFILE)
    mocker.patch.dict(
        os.environ,
        {
            "FACULTY_DOMAIN": "other.domain.com",
            "FACULTY_PROTOCOL": "other-protocol",
            "FACULTY_CLIENT_ID": "other-client-id",
            "FACULTY_CLIENT_SECRET": "other-client-secret",
        },
    )
    assert config.resolve_profile() == OTHER_PROFILE
Esempio n. 11
0
def test_resolve_profile_env_sherlockml(mocker):
    mocker.patch("faculty.config.resolve_credentials_path")
    mocker.patch("faculty.config.load_profile", return_value=DEFAULT_PROFILE)
    mocker.patch.dict(
        os.environ,
        {
            "SHERLOCKML_DOMAIN": "other.domain.com",
            "SHERLOCKML_PROTOCOL": "other-protocol",
            "SHERLOCKML_CLIENT_ID": "other-client-id",
            "SHERLOCKML_CLIENT_SECRET": "other-client-secret",
        },
    )
    with pytest.warns(UserWarning) as records:
        assert config.resolve_profile() == OTHER_PROFILE

    assert len(records) == 4
    assert "SHERLOCKML_DOMAIN is deprecated" in str(records[0].message)
    assert "SHERLOCKML_PROTOCOL is deprecated" in str(records[1].message)
    assert "SHERLOCKML_CLIENT_ID is deprecated" in str(records[2].message)
    assert "SHERLOCKML_CLIENT_SECRET is deprecated" in str(records[3].message)