def test_resource_exists_case2(self, \
        mock_service_account, \
        mock_storage, \
        mock_settings, \
        mock_exists, \
        mock_make_local_directory):
        '''
        Tests the case where we don't have access to the object
        in the bucket since the bucket permissions block our access.
        Note, however, that you can encounter situations where the bucket
        access is blocked, but the actual object IS public. We handle
        that case elsewhere.
        '''

        os.environ['STORAGE_BUCKET_NAME'] = DUMMY_BUCKETNAME
        storage_backend = GoogleBucketStorage()

        mock_client = mock.MagicMock()
        storage_backend.storage_client = mock_client

        mock_client.get_bucket.side_effect = google.api_core.exceptions.Forbidden(
            'ack!')

        with self.assertRaises(google.api_core.exceptions.Forbidden):
            storage_backend.get_bucket('foo')
        self.assertFalse(
            storage_backend.resource_exists('gs://foo/something.txt'))
    def test_resource_exists_case1(self, \
        mock_service_account, \
        mock_storage, \
        mock_settings, \
        mock_exists, \
        mock_make_local_directory):
        '''
        Test the case where the object is not found since the bucket
        is not found by the google api client.
        '''

        os.environ['STORAGE_BUCKET_NAME'] = DUMMY_BUCKETNAME
        storage_backend = GoogleBucketStorage()

        mock_client = mock.MagicMock()
        storage_backend.storage_client = mock_client

        mock_client.get_bucket.side_effect = google.api_core.exceptions.NotFound(
            'ack!')

        with self.assertRaises(google.api_core.exceptions.NotFound):
            storage_backend.get_bucket('foo')

        self.assertFalse(
            storage_backend.resource_exists('gs://foo/something.txt'))