コード例 #1
0
    def workspaces(self) -> List[Workspace]:
        """
        Fetch all workspaces (or a subset if desired) from a particular Terraform organization. The
        workspaces will be fetched on a as-needed basis; they will be cached so this property
        computes in constant-time on subsequent accesses. If configuration options are updated on
        this Terraform class instance, the workspaces will be re-fetched the next time this property
        is accessed.

        :return: The fetched workspaces, if any. If the configuration in this Terraform instance is
                 not valid, an empty list will be returned.
        """

        if self._workspace_cache is None or self._options_hash != self._compute_options_hash(
        ):
            if not self.configuration_is_valid():
                return []
            self._options_hash = self._compute_options_hash()
            self._workspace_cache = fetch_all(
                self.terraform_domain,
                self.organization,
                workspace_names=self.workspace_names,
                blacklist=self.blacklist,
                token=self.token,
                write_error_messages=self.write_output)
        return self._workspace_cache
コード例 #2
0
def test_fetch_all_workspaces_bad_json_response(mocker: MockerFixture) -> None:
    _establish_mocks(mocker)
    for test in [{}, {"data": {"bad json": "test"}}]:
        responses.add(responses.GET,
                      f"{_test_api_url}?page[size]=100&page[number]=1",
                      match_querystring=True,
                      json=test,
                      status=200)
        assert fetch_all(TEST_TERRAFORM_DOMAIN, _test_organization) == []
コード例 #3
0
def test_fetch_all_workspaces(mocker: MockerFixture) -> None:
    _establish_mocks(mocker)
    responses.add(responses.GET,
                  f"{_test_api_url}?page[size]=100&page[number]=1",
                  match_querystring=True,
                  json=_test_json,
                  status=200)
    assert fetch_all(TEST_TERRAFORM_DOMAIN, _test_organization) == [
        _test_workspace1, _test_workspace2
    ]
コード例 #4
0
def test_fetch_all_workspaces_with_inverted_wildcard_filter(
        mocker: MockerFixture) -> None:
    _establish_mocks(mocker)
    responses.add(responses.GET,
                  f"{_test_api_url}?page[size]=100&page[number]=1",
                  match_querystring=True,
                  json=_test_json,
                  status=200)
    assert fetch_all(TEST_TERRAFORM_DOMAIN,
                     _test_organization,
                     workspace_names=["*"],
                     blacklist=True) == []