Esempio n. 1
0
 def test_persist(self):
     assert_gcs_environ()
     uri = os.environ.get('GCS_TEST_FILE_URI')
     if not uri:
         raise unittest.SkipTest("No GCS URI available for testing")
     data = b"TestGCSFilesStore: \xe2\x98\x83"
     buf = BytesIO(data)
     meta = {'foo': 'bar'}
     path = 'full/filename'
     store = GCSFilesStore(uri)
     store.POLICY = 'authenticatedRead'
     expected_policy = {'role': 'READER', 'entity': 'allAuthenticatedUsers'}
     yield store.persist_file(path, buf, info=None, meta=meta, headers=None)
     s = yield store.stat_file(path, info=None)
     self.assertIn('last_modified', s)
     self.assertIn('checksum', s)
     self.assertEqual(s['checksum'], 'zc2oVgXkbQr2EQdSdw3OPA==')
     u = urlparse(uri)
     content, acl, blob = get_gcs_content_and_delete(
         u.hostname, u.path[1:] + path)
     self.assertEqual(content, data)
     self.assertEqual(blob.metadata, {'foo': 'bar'})
     self.assertEqual(blob.cache_control, GCSFilesStore.CACHE_CONTROL)
     self.assertEqual(blob.content_type, 'application/octet-stream')
     self.assertIn(expected_policy, acl)
 def test_persist(self):
     assert_gcs_environ()
     uri = os.environ.get('GCS_TEST_FILE_URI')
     if not uri:
         raise unittest.SkipTest("No GCS URI available for testing")
     data = b"TestGCSFilesStore: \xe2\x98\x83"
     buf = BytesIO(data)
     meta = {'foo': 'bar'}
     path = 'full/filename'
     store = GCSFilesStore(uri)
     yield store.persist_file(path, buf, info=None, meta=meta, headers=None)
     s = yield store.stat_file(path, info=None)
     self.assertIn('last_modified', s)
     self.assertIn('checksum', s)
     self.assertEqual(s['checksum'], 'zc2oVgXkbQr2EQdSdw3OPA==')
     u = urlparse(uri)
     content, blob = get_gcs_content_and_delete(u.hostname, u.path[1:]+path)
     self.assertEqual(content, data)
     self.assertEqual(blob.metadata, {'foo': 'bar'})
     self.assertEqual(blob.cache_control, GCSFilesStore.CACHE_CONTROL)
     self.assertEqual(blob.content_type, 'application/octet-stream')