|
23 | 23 |
|
24 | 24 | import google.cloud.storage.blob |
25 | 25 | import mock |
| 26 | +import pytest |
26 | 27 | import six |
27 | 28 | from six.moves import http_client |
28 | 29 |
|
@@ -3171,6 +3172,41 @@ def test_updated_unset(self): |
3171 | 3172 | blob = self._make_one("blob-name", bucket=BUCKET) |
3172 | 3173 | self.assertIsNone(blob.updated) |
3173 | 3174 |
|
| 3175 | + def test_from_string_w_valid_uri(self): |
| 3176 | + from google.cloud.storage.blob import Blob |
| 3177 | + |
| 3178 | + connection = _Connection() |
| 3179 | + client = _Client(connection) |
| 3180 | + uri = "gs://BUCKET_NAME/b" |
| 3181 | + blob = Blob.from_string(uri, client) |
| 3182 | + |
| 3183 | + self.assertIsInstance(blob, Blob) |
| 3184 | + self.assertIs(blob.client, client) |
| 3185 | + self.assertEqual(blob.name, "b") |
| 3186 | + self.assertEqual(blob.bucket.name, "BUCKET_NAME") |
| 3187 | + |
| 3188 | + def test_from_string_w_invalid_uri(self): |
| 3189 | + from google.cloud.storage.blob import Blob |
| 3190 | + |
| 3191 | + connection = _Connection() |
| 3192 | + client = _Client(connection) |
| 3193 | + |
| 3194 | + with pytest.raises(ValueError, match="URI scheme must be gs"): |
| 3195 | + Blob.from_string("http://bucket_name/b", client) |
| 3196 | + |
| 3197 | + def test_from_string_w_domain_name_bucket(self): |
| 3198 | + from google.cloud.storage.blob import Blob |
| 3199 | + |
| 3200 | + connection = _Connection() |
| 3201 | + client = _Client(connection) |
| 3202 | + uri = "gs://buckets.example.com/b" |
| 3203 | + blob = Blob.from_string(uri, client) |
| 3204 | + |
| 3205 | + self.assertIsInstance(blob, Blob) |
| 3206 | + self.assertIs(blob.client, client) |
| 3207 | + self.assertEqual(blob.name, "b") |
| 3208 | + self.assertEqual(blob.bucket.name, "buckets.example.com") |
| 3209 | + |
3174 | 3210 |
|
3175 | 3211 | class Test__quote(unittest.TestCase): |
3176 | 3212 | @staticmethod |
|
0 commit comments