def test_access_token_not_set_raises_exception(self): """ Test that exception is raised if no access token is set """ with pytest.raises(NoAcccessTokenException): buildkite = Buildkite() buildkite.agents()
def test_access_token_set(self): """ Test that methods can be called when access token is set """ buildkite = Buildkite() buildkite.set_access_token("FAKE-ACCESS-TOKEN") assert buildkite.agents()
# For example, you can put "windows" there to restart Windows agents. import os from pybuildkite.buildkite import Buildkite from requests.exceptions import HTTPError FILTER = "docker" ORGANIZATION = "bazel" print("Using Buildkite API Token: {}".format(os.environ["BUILDKITE_TOKEN"])) buildkite = Buildkite() buildkite.set_access_token(os.environ["BUILDKITE_TOKEN"]) response = buildkite.agents().list_all(organization=ORGANIZATION, page=1, with_pagination=True) agents = response.body # Keep looping until next_page is not populated while response.next_page: response = buildkite.agents().list_all(organization=ORGANIZATION, page=response.next_page, with_pagination=True) agents += response.body for agent in agents: if FILTER in agent["name"]: print( "Stopping agent {} (https://buildkite.com/organizations/{}/agents/{}): " .format(agent["name"], ORGANIZATION, agent["id"]),