docs: fix issues
[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
33     def test_urlutils_join_url(self):
34         self.assertEqual(
35             self.url_utils.join_url("http://github.com/proj1", "proj2"),
36             "http://github.com/proj2")
37         self.assertEqual(
38             self.url_utils.join_url("http://github.com/proj1/scripts/a.js",
39                                     "b.js"),
40             "http://github.com/proj1/scripts/b.js")
41         self.assertEqual(
42             self.url_utils.join_url("http://github.com/proj1/scripts", "b.js"),
43             "http://github.com/proj1/b.js")
44         self.assertEqual(
45             self.url_utils.join_url("http://github.com/proj1/scripts",
46                                     "scripts/b.js"),
47             "http://github.com/proj1/scripts/b.js")