示例#1
0
 def test_access_token_setting(self):
     """
     Test functionality of is_acces_token_set
     """
     client = Client()
     assert not client.is_access_token_set()
     client.set_client_access_token("FAKE-TOKEN")
     assert client.is_access_token_set()
示例#2
0
class BuildKite(object):
    def __init__(self):
        """

        :param access_token:
        """
        self.client = Client()
        self.base_url = "https://api.buildkite.com/v2/"

    def set_access_token(self, access_token):
        """

        :param access_token:
        :return:
        """
        self.client.set_client_access_token(access_token)

    def requires_token(func):
        def wrapper(self, *args, **kwargs):
            if not self.client.is_access_token_set():
                raise NoAcccessTokenException
            else:
                return func(self, *args, **kwargs)

        return wrapper

    @requires_token
    def organizations(self):
        return Organizations(self.client, self.base_url)

    @requires_token
    def pipelines(self):
        return Pipelines(self.client, self.base_url)

    @requires_token
    def builds(self):
        return Builds(self.client, self.base_url)

    @requires_token
    def jobs(self):
        return Jobs(self.client, self.base_url)

    @requires_token
    def agents(self):
        return Agents(self.client, self.base_url)
示例#3
0
    def test_request_should_include_token_when_set(self):
        """
        Test that the access token is not included in the call to
        requests if it isn't actually set.
        """
        fake_client = Client()
        fake_client.set_client_access_token("ABCDEF1234")

        with patch("requests.request") as request:
            request.return_value.json.return_value = {"key": "value"}

            ret = fake_client.request("GET", "http://www.google.com/")

        expected_params = b"per_page=100"
        request.assert_called_once_with(
            "GET",
            "http://www.google.com/",
            headers={"Authorization": "Bearer ABCDEF1234"},
            json=None,
            params=expected_params,
        )
示例#4
0
    def test_request_should_include_token_when_set(self):
        """
        Test that the access token is not included in the call to
        requests if it isn't actually set.
        """
        client = Client()
        client.set_client_access_token("ABCDEF1234")

        with patch("requests.request") as request:
            request.return_value.json.return_value = {}

            client.request("GET", "http://www.google.com/")

        expected_params = {"access_token": "ABCDEF1234"}
        request.assert_called_once_with(
            "GET",
            "http://www.google.com/",
            headers=None,
            json=None,
            params=expected_params,
        )
示例#5
0
class Buildkite(object):
    """
    Public API for Buildkite
    """

    def __init__(self):
        """
        Create a new client
        """
        self.client = Client()
        self.base_url = "https://api.buildkite.com/v2/"

    def set_access_token(self, access_token):
        """
        Set the access token to be used to authenticate the requests
        :param access_token: The access token
        """
        self.client.set_client_access_token(access_token)

    @requires_token
    def organizations(self):
        """
        Get Organization operations for the Buildkite API

        :return: Client
        """
        return Organizations(self.client, self.base_url)

    @requires_token
    def pipelines(self):
        """
        Get Pipeline operations for the Buildkite API

        :return: Client
        """
        return Pipelines(self.client, self.base_url)

    @requires_token
    def builds(self):
        """
        Get Build operations for the Buildkite API

        :return: Client
        """
        return Builds(self.client, self.base_url)

    @requires_token
    def jobs(self):
        """
        Get Job operations for the Buildkite API

        :return: Client
        """
        return Jobs(self.client, self.base_url)

    @requires_token
    def agents(self):
        """
        Get Agent operations for the Buildkite API

        :return: Client
        """
        return Agents(self.client, self.base_url)

    @requires_token
    def emojis(self):
        """
        Get Emoji operations for the Buildkite API
        """
        return Emojis(self.client, self.base_url)

    @requires_token
    def annotations(self):
        """
        Get Annotation operations for the Buildkite API
        """
        return Annotations(self.client, self.base_url)

    @requires_token
    def artifacts(self):
        """
        Get Artifact operations for the Buildkite API
        """
        return Artifacts(self.client, self.base_url)

    @requires_token
    def teams(self):
        """
        Get Team operations for the Buildkite API
        """
        return Teams(self.client, self.base_url)

    @requires_token
    def users(self):
        """
        Get User operations for the Buildkite API
        """
        return Users(self.client, self.base_url)
示例#6
0
class BuildKite(object):
    """
    Public API for Buildkite
    """
    def __init__(self):
        """
        Create a new client
        """
        self.client = Client()
        self.base_url = "https://api.buildkite.com/v2/"

    def set_access_token(self, access_token):
        """
        Set the access token to be used to authenticate the requests
        :param access_token: The access token
        """
        self.client.set_client_access_token(access_token)

    def requires_token(func):
        """
        This annotation protects API calls that require authentication.

        It will cause them to raise NoAcccessTokenException if the token is not set in the client.

        :return: Function decorated with the protection
        """
        def wrapper(self, *args, **kwargs):
            """
            Call func or raise NoAcccessTokenException if no access token is set

            :param self:
            :param args: Optional
            :param kwargs: Optional

            :raises NoAcccessTokenException: If no access token is set
            :return:
            """
            if not self.client.is_access_token_set():
                raise NoAcccessTokenException
            else:
                return func(self, *args, **kwargs)

        return wrapper

    @requires_token
    def organizations(self):
        """
        Get Organisation operations for the Buildkite API

        :return: Client
        """
        return Organizations(self.client, self.base_url)

    @requires_token
    def pipelines(self):
        """
        Get Pipeline operations for the Buildkite API

        :return: Client
        """
        return Pipelines(self.client, self.base_url)

    @requires_token
    def builds(self):
        """
        Get Build operations for the Buildkite API

        :return: Client
        """
        return Builds(self.client, self.base_url)

    @requires_token
    def jobs(self):
        """
        Get Job operations for the Buildkite API

        :return: Client
        """
        return Jobs(self.client, self.base_url)

    @requires_token
    def agents(self):
        """
        Get Agent operations for the Buildkite API

        :return: Client
        """
        return Agents(self.client, self.base_url)

    @requires_token
    def emojis(self):
        """
        Get Emoji operations for the Buildkite API

        :return: Client
        """
        return Emojis(self.client, self.base_url)

    def annotations(self):
        """
        Get Annotation operations for the Buildkite API
        """
        return Annotations(self.client, self.base_url)