Ejemplo n.º 1
0
 def setUp(self) -> None:
     super(CloudStorageEmulatorUnitTests, self).setUp()
     self.emulator = cloud_storage_emulator.CloudStorageEmulator()
     self.emulator.namespace = 'namespace'
     self.emulator.reset()
     self.blob1 = cloud_storage_emulator.EmulatorBlob(
         '/file/path.png', b'data', 'image/png')
     self.blob2 = cloud_storage_emulator.EmulatorBlob(
         '/file/path2.png', b'data2', 'image/png')
     self.blob3 = cloud_storage_emulator.EmulatorBlob(
         '/different/path.png', b'data2', 'image/png')
 def test_repr_returns_correct_string_representation(self) -> None:
     orig_blob = (
         cloud_storage_emulator.EmulatorBlob('name', 'string', 'image/png'))
     self.assertEqual(
         orig_blob.__repr__(),
         'EmulatorBlob(name=name, content_type=image/png)'
     )
Ejemplo n.º 3
0
 def test_to_dict_returns_correct_dictionary(self) -> None:
     blob = (cloud_storage_emulator.EmulatorBlob('name', b'string',
                                                 'image/png'))
     self.assertEqual(
         blob.to_dict(), {
             b'name': b'name',
             b'raw_bytes': b'string',
             b'content_type': b'image/png'
         })
Ejemplo n.º 4
0
 def test_create_copy_creates_identical_copy(self) -> None:
     orig_blob = (cloud_storage_emulator.EmulatorBlob(
         'name', 'string', 'image/png'))
     copy_blob = (cloud_storage_emulator.EmulatorBlob.create_copy(
         orig_blob, 'new'))
     self.assertNotEqual(orig_blob, copy_blob)
     self.assertNotEqual(orig_blob.name, copy_blob.name)
     self.assertEqual(orig_blob.download_as_bytes(),
                      copy_blob.download_as_bytes())
     self.assertEqual(orig_blob.content_type, copy_blob.content_type)
 def test_from_dict_returns_blob(self) -> None:
     blob = (
         cloud_storage_emulator.EmulatorBlob('name', b'string', 'image/png'))
     self.assertEqual(
         blob,
         cloud_storage_emulator.EmulatorBlob.from_dict({
             b'name': b'name',
             b'raw_bytes': b'string',
             b'content_type': b'image/png'
         })
     )
Ejemplo n.º 6
0
def commit(unused_bucket_name: str, filepath: str,
           raw_bytes: Union[bytes, str], mimetype: str) -> None:
    """Commits bytes to the relevant file.

    Args:
        unused_bucket_name: str. Unused name of the GCS bucket.
        filepath: str. The path to the relevant file.
        raw_bytes: bytes|str. The content to be stored in the file.
        mimetype: str. The content-type of the file.
    """
    # TODO(#13500): Refactor this method that only bytes are passed
    # into raw_bytes.
    blob = cloud_storage_emulator.EmulatorBlob(filepath,
                                               raw_bytes,
                                               content_type=mimetype)
    CLIENT.upload_blob(filepath, blob)
Ejemplo n.º 7
0
 def test_compare_blob_and_int_is_false(self) -> None:
     orig_blob = (cloud_storage_emulator.EmulatorBlob(
         'name', 'string', 'image/png'))
     self.assertFalse(orig_blob == 1)
Ejemplo n.º 8
0
 def test_init_blob_with_wrong_mimetype_raise_exception(self) -> None:
     with self.assertRaisesRegexp(  # type: ignore[no-untyped-call]
             Exception, 'Content type contains unknown MIME type.'):
         cloud_storage_emulator.EmulatorBlob('name', b'string', 'png')
Ejemplo n.º 9
0
 def test_init_blob_with_bytes_creates_blob(self) -> None:
     blob = (cloud_storage_emulator.EmulatorBlob('name', b'string',
                                                 'image/png'))
     self.assertEqual(blob.name, 'name')
     self.assertEqual(blob.download_as_bytes(), b'string')
     self.assertEqual(blob.content_type, 'image/png')
Ejemplo n.º 10
0
 def test_init_blob_with_none_content_type_creates_blob(self) -> None:
     blob = (cloud_storage_emulator.EmulatorBlob('name', 'string', None))
     self.assertEqual(blob.name, 'name')
     self.assertEqual(blob.download_as_bytes(), b'string')
     self.assertEqual(blob.content_type, 'application/octet-stream')