1# -*- coding: utf-8 -*-
2# Copyright 2014 Google Inc.  All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.   .
15"""Unit tests for storage URLs."""
16
17from __future__ import absolute_import
18from __future__ import print_function
19from __future__ import division
20from __future__ import unicode_literals
21
22import os
23
24from gslib import storage_url
25import gslib.tests.testcase as testcase
26
27
28class TestStorageUrl(testcase.GsUtilUnitTestCase):
29  """Unit tests for storage URLs."""
30
31  def setUp(self):
32    super(TestStorageUrl, self).setUp()
33
34  def test_is_file_url_string(self):
35    self.assertTrue(storage_url.IsFileUrlString('abc'))
36    self.assertTrue(storage_url.IsFileUrlString('file://abc'))
37    self.assertFalse(storage_url.IsFileUrlString('gs://abc'))
38    self.assertFalse(storage_url.IsFileUrlString('s3://abc'))
39
40  def test_storage_url_from_string(self):
41    url = storage_url.StorageUrlFromString('abc')
42    self.assertTrue(url.IsFileUrl())
43    self.assertEquals('abc', url.object_name)
44
45    url = storage_url.StorageUrlFromString('file://abc/123')
46    self.assertTrue(url.IsFileUrl())
47    self.assertEquals('abc%s123' % os.sep, url.object_name)
48
49    url = storage_url.StorageUrlFromString('gs://abc/123/456')
50    self.assertTrue(url.IsCloudUrl())
51    self.assertEquals('abc', url.bucket_name)
52    self.assertEquals('123/456', url.object_name)
53
54    url = storage_url.StorageUrlFromString('s3://abc/123/456')
55    self.assertTrue(url.IsCloudUrl())
56    self.assertEquals('abc', url.bucket_name)
57    self.assertEquals('123/456', url.object_name)
58