def test_gcs_bucket_wildcard_and_object_wildcard(self, fields_scope,
                                                     client):
        """Test multiple object matches in multiple buckets."""
        self.bucket1_object = test_resources.get_object_resource(
            storage_url.ProviderPrefix.GCS, 'bucket1', 'a.txt')
        self.bucket2_object = test_resources.get_object_resource(
            storage_url.ProviderPrefix.GCS, 'bucket2', 'a.txt')
        client.list_buckets.side_effect = [self.buckets_response]
        client.list_objects.side_effect = [[self.bucket1_object],
                                           [self.bucket2_object]]

        resource_iterator = wildcard_iterator.get_wildcard_iterator(
            'gs://bucket*/*', fields_scope=fields_scope)

        self.assertEqual(list(resource_iterator),
                         [self.bucket1_object, self.bucket2_object])
        client.list_buckets.assert_called_once_with(
            cloud_api.FieldsScope(fields_scope))
        client.list_objects.mock_calls = [
            mock.call(all_versions=False,
                      bucket_name='bucket1',
                      delimiter='/',
                      fields_scope=fields_scope,
                      prefix=None),
            mock.call(all_versions=False,
                      bucket_name='bucket2',
                      delimiter='/',
                      fields_scope=fields_scope,
                      prefix=None)
        ]
    def test_gcs_bucket_url_without_wildcard(self, fields_scope, client):
        """Test bucket with no bucket-level expansion."""
        client.get_bucket.side_effect = [self.buckets_response[0]]

        resource_iterator = wildcard_iterator.get_wildcard_iterator(
            'gs://bucket1', fields_scope=fields_scope)
        expected = self.buckets_response[:1]

        self.assertEqual(list(resource_iterator), expected)
        client.get_bucket.assert_called_once_with(
            self.bucket1.name, cloud_api.FieldsScope(fields_scope))
    def test_gcs_bucket_url_with_wildcard_gets_all_buckets(
            self, fields_scope, client):
        """Test multiple bucket with bucket-level expansion."""
        client.list_buckets.side_effect = [self.buckets_response]

        resource_iterator = wildcard_iterator.get_wildcard_iterator(
            'gs://bucket*', fields_scope=fields_scope)

        self.assertEqual(list(resource_iterator), self.buckets_response)
        client.list_buckets.assert_called_once_with(
            cloud_api.FieldsScope(fields_scope))
    def test_gcs_root_listing(self, fields_scope, client):
        """Test retrieving provider URL with no specified resource."""
        client.list_buckets.side_effect = [self.buckets_response]

        resource_iterator = wildcard_iterator.get_wildcard_iterator(
            'gs://', fields_scope=fields_scope)
        actual = [resource.metadata.name for resource in resource_iterator]
        expected = [b.name for b in self.buckets]
        self.assertEqual(actual, expected)

        client.list_buckets.assert_called_once_with(
            cloud_api.FieldsScope(fields_scope))
    def test_gcs_bucket_url_with_wildcard_gets_single_bucket(
            self, fields_scope, client):
        """Test single bucket with bucket-level expansion."""
        client.list_buckets.side_effect = [self.buckets_response]

        resource_iterator = wildcard_iterator.get_wildcard_iterator(
            'gs://buck*1', fields_scope=fields_scope)

        self.assertEqual(
            list(resource_iterator),
            [gcs_api._bucket_resource_from_metadata(self.bucket1)])
        client.list_buckets.assert_called_once_with(
            cloud_api.FieldsScope(fields_scope))