Example #1
0
    def test_request_no_payload_token(self, mocker):
        request = mocker.patch.object(http, "request")
        request.side_effect = (
            http.Response(200, '{"access_token": "token"}'),
            http.Response(200, "data"),
        )

        client.Client(
            "http://example.com/",
            "user",
            "pass",
            None,
            True,
            "/ca",
        ).request("PUT", "/path")

        request.assert_called_with(
            "PUT",
            "http://example.com/path",
            payload=None,
            headers=dict(Authorization="Bearer token"),
            validate_certs=True,
            ca_path="/ca",
        )
Example #2
0
    def test_login_failure_missing_token(self, mocker):
        request = mocker.patch.object(http, "request")
        request.return_value = http.Response(200, '{"access_bla": "token"}')

        with pytest.raises(errors.SensuError, match="token"):
            client.Client("http://example.com/", "user", "pass").token
Example #3
0
    def test_login_failure_bad_json(self, mocker):
        request = mocker.patch.object(http, "request")
        request.return_value = http.Response(200, "{ not a json }")

        with pytest.raises(errors.SensuError, match="JSON"):
            client.Client("http://example.com/", "user", "pass").token
Example #4
0
    def test_missing_backend_version_in_response(self, mocker):
        c = client.Client("http://example.com/", "u", "p", None, True, None)
        mocker.patch.object(c, "get").return_value = http.Response(200, '{}')

        with pytest.raises(errors.SensuError, match="backend"):
            c.version
Example #5
0
def get_sensu_client(auth):
    return client.Client(auth["url"], auth["user"], auth["password"])
Example #6
0
    def test_login_failure(self, mocker):
        open_url = mocker.patch.object(client, "open_url")
        open_url.side_effect = URLError("Invalid")

        with pytest.raises(errors.ClientError):
            client.Client("http://example.com/", "user", "pass").token