Skip to content

Instantly share code, notes, and snippets.

@franksands
Created January 24, 2020 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franksands/65e5bcc56c56f678aa012281e1d5de22 to your computer and use it in GitHub Desktop.
Save franksands/65e5bcc56c56f678aa012281e1d5de22 to your computer and use it in GitHub Desktop.
list files in cloud store
import os
import sys
import unittest
import cloudstorage
GOOGLE_APP_ENGINE_PATH = os.environ.get("GAE_PATH")
sys.path.append(GOOGLE_APP_ENGINE_PATH + 'lib/yaml-3.10')
from google.appengine.ext import testbed
class CloudStorageTestCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.testbed = testbed.Testbed()
cls.testbed.activate()
cls.testbed.init_app_identity_stub()
cls.testbed.init_memcache_stub()
cls.testbed.init_blobstore_stub()
cls.testbed.init_urlfetch_stub()
cls.testbed.init_datastore_v3_stub()
def test_list_files(self):
with cloudstorage.open('/default/test/test1.json', 'w', content_type='application/json') as fout:
fout.write('{"id": "test 1"}')
with cloudstorage.open('/default/test/test2.json', 'w', content_type='application/json') as fout:
fout.write('{"id": "test 2"}')
files = cloudstorage.listbucket('/default/test')
for file in files:
print file.filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment