コード例 #1
0
 def test_project_ids_list(self, mock_exclusions_from_bucket, mock_client):
     # Import Project class from Google Cloud Resource Manager
     from google.cloud.resource_manager.project import Project
     # Create dummy client object to use in mock projects
     client = object()
     # Mock return value of exclusions_from_bucket
     mock_exclusions_from_bucket.return_value = ['654321', '123456', 'xpn']
     mock_exclusions_from_bucket = mock.MagicMock()
     # Test Case Project A
     project_a_id = "python-test-case"
     display_name = "Python Test Case"
     labels = {"foo": "bar"}
     mock_project_a = Project(project_a_id,
                              client,
                              name=display_name,
                              labels=labels)
     # Test Case Project B
     project_b_id = "test-xpn"
     display_name = "Test Exclusion"
     mock_project_b = Project(project_b_id,
                              client,
                              name=display_name,
                              labels=labels)
     # Test Case List of Projects
     projects_list = [mock_project_a, mock_project_b]
     # Mock client.list_projects()
     mock_client.return_value.list_projects.return_value = projects_list
     mock_client = mock.MagicMock()
     # Execute function and store the output in a variable
     folder_id = "987654321"
     result = project_ids_list(folder_id)
     # Assert first return value is 'python-test-case'
     self.assertEqual(result[0], 'python-test-case')
     # Assert length is only one project (one gets excluded)
     self.assertEqual(len(result), 1)
コード例 #2
0
    def new_project(self, project_id, name=None, labels=None):
        """Create a project bound to the current client.

        Use :meth:`Project.reload() \
        <google.cloud.resource_manager.project.Project.reload>` to retrieve
        project metadata after creating a
        :class:`~google.cloud.resource_manager.project.Project` instance.

        .. note:

            This does not make an API call.

        :type project_id: str
        :param project_id: The ID for this project.

        :type name: str
        :param name: The display name of the project.

        :type labels: dict
        :param labels: A list of labels associated with the project.

        :rtype: :class:`~google.cloud.resource_manager.project.Project`
        :returns: A new instance of a
                  :class:`~google.cloud.resource_manager.project.Project`
                  **without** any metadata loaded.
        """
        return Project(project_id=project_id,
                       client=self,
                       name=name,
                       labels=labels)
コード例 #3
0
ファイル: client.py プロジェクト: ofek/google-cloud-python
    def get_items_from_response(self, response):
        """Yield :class:`.Project` items from response.

        :type response: dict
        :param response: The JSON API response for a page of projects.
        """
        for resource in response.get('projects', []):
            item = Project.from_api_repr(resource, client=self.client)
            yield item
コード例 #4
0
ファイル: client.py プロジェクト: tmatsuo/gcloud-python
    def get_items_from_response(self, response):
        """Yield projects from response.

        :type response: dict
        :param response: The JSON API response for a page of projects.
        """
        for resource in response.get('projects', []):
            item = Project.from_api_repr(resource, client=self.client)
            yield item
コード例 #5
0
    def _item_to_value(self, resource):
        """Convert a JSON project to the native object.

        :type resource: dict
        :param resource: An resource to be converted to a project.

        :rtype: :class:`.Project`
        :returns: The next project in the page.
        """
        return Project.from_api_repr(resource, client=self._parent.client)
コード例 #6
0
def _item_to_project(iterator, resource):
    """Convert a JSON project to the native object.

    :type iterator: :class:`~google.api_core.page_iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: A resource to be converted to a project.

    :rtype: :class:`.Project`
    :returns: The next project in the page.
    """
    return Project.from_api_repr(resource, client=iterator.client)
コード例 #7
0
ファイル: client.py プロジェクト: tswast/gcloud-python
def _item_to_project(iterator, resource):
    """Convert a JSON project to the native object.

    :type iterator: :class:`~google.api_core.page_iterator.Iterator`
    :param iterator: The iterator that has retrieved the item.

    :type resource: dict
    :param resource: A resource to be converted to a project.

    :rtype: :class:`.Project`
    :returns: The next project in the page.
    """
    return Project.from_api_repr(resource, client=iterator.client)