Support python3 uploaded to pypi websit
[parser.git] / tosca2heat / tosca-parser / toscaparser / tests / test_utils.py
1 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
2 #    not use this file except in compliance with the License. You may obtain
3 #    a copy of the License at
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
7 #    Unless required by applicable law or agreed to in writing, software
8 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 #    License for the specific language governing permissions and limitations
11 #    under the License.
12
13 from toscaparser.tests.base import TestCase
14 import toscaparser.utils.urlutils
15 import toscaparser.utils.yamlparser
16
17 YAML_LOADER = toscaparser.utils.yamlparser.load_yaml
18
19
20 class UrlUtilsTest(TestCase):
21
22     url_utils = toscaparser.utils.urlutils.UrlUtils
23
24     def test_urlutils_validate_url(self):
25         self.assertTrue(self.url_utils.validate_url("http://www.github.com/"))
26         self.assertTrue(
27             self.url_utils.validate_url("https://github.com:81/a/2/a.b"))
28         self.assertTrue(self.url_utils.validate_url("ftp://github.com"))
29         self.assertFalse(self.url_utils.validate_url("github.com"))
30         self.assertFalse(self.url_utils.validate_url("123"))
31         self.assertFalse(self.url_utils.validate_url("a/b/c"))
32         self.assertTrue(self.url_utils.validate_url("file:///dir/file.ext"))
33
34     def test_urlutils_join_url(self):
35         self.assertEqual(
36             self.url_utils.join_url("http://github.com/proj1", "proj2"),
37             "http://github.com/proj2")
38         self.assertEqual(
39             self.url_utils.join_url("http://github.com/proj1/scripts/a.js",
40                                     "b.js"),
41             "http://github.com/proj1/scripts/b.js")
42         self.assertEqual(
43             self.url_utils.join_url("http://github.com/proj1/scripts", "b.js"),
44             "http://github.com/proj1/b.js")
45         self.assertEqual(
46             self.url_utils.join_url("http://github.com/proj1/scripts",
47                                     "scripts/b.js"),
48             "http://github.com/proj1/scripts/b.js")