Exemple #1
0
def test_get_management_token_ok():
    config = Mock(
        keycloak={
            "base_path": "http://kc_base_path/",
            "ignore_realm": "master",
            "credentials": {
                "username": "******",
                "password": "******",
                "client_id": "admin-cli",
                "grant_type": "password",
            }
        })
    mock_self = Mock(config=config)

    response = requests.Response()

    def json_func():
        return {"access_token": "xyz"}

    response.json = json_func
    patch_http_perform = patch("requests.post", return_value=response)
    with patch_http_perform as mock_http_perform:
        token = Auth.get_management_token(mock_self)
        mock_http_perform.assert_called_with(
            'http://kc_base_path/realms/master/protocol/openid-connect/token',
            data=mock_self.config.keycloak['credentials'])
        assert token == "xyz"
Exemple #2
0
def test_get_management_token_ok():
    config = Mock(dojot={
        "management": {
            "user": "******",
            "tenant": "sample-tenant"
        }
    })
    mock_self = Mock(config=config)
    token = Auth.get_management_token(mock_self)
    assert token is not None
Exemple #3
0
def test_get_management_token_fail():
    config = Mock(
        keycloak={
            "base_path": "http://kc_base_path/",
            "ignore_realm": "master",
            "credentials": {
                "username": "******",
                "password": "******",
                "client_id": "admin-cli",
                "grant_type": "password",
            }
        })

    mock_self = Mock(config=config)

    patch_http_perform = patch("requests.post")
    with patch_http_perform as mock_http_perform:
        mock_http_perform.side_effect = requests.exceptions.ConnectionError()
        with pytest.raises(Exception):
            Auth.get_management_token(mock_self)