Support version of tosca_simple_yaml_1_1
[parser.git] / tosca2heat / tosca-parser / toscaparser / tests / test_validate_tosca_version.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.common.exception import (
14     InvalidTOSCAVersionPropertyException)
15 from toscaparser.tests.base import TestCase
16 from toscaparser.utils.gettextutils import _
17 from toscaparser.utils.validateutils import TOSCAVersionProperty
18
19
20 class TOSCAVersionPropertyTest(TestCase):
21
22     def test_tosca_version_property(self):
23         version = '18.0.3.beta-1'
24         expected_output = '18.0.3.beta-1'
25         output = TOSCAVersionProperty(version).get_version()
26         self.assertEqual(output, expected_output)
27
28         version = 18
29         expected_output = '18.0'
30         output = TOSCAVersionProperty(version).get_version()
31         self.assertEqual(output, expected_output)
32
33         version = 18.0
34         expected_output = '18.0'
35         output = TOSCAVersionProperty(version).get_version()
36         self.assertEqual(output, expected_output)
37
38         version = '18.0.3'
39         expected_output = '18.0.3'
40         output = TOSCAVersionProperty(version).get_version()
41         self.assertEqual(output, expected_output)
42
43         version = 0
44         expected_output = None
45         output = TOSCAVersionProperty(version).get_version()
46         self.assertEqual(output, expected_output)
47
48         version = 00
49         expected_output = None
50         output = TOSCAVersionProperty(version).get_version()
51         self.assertEqual(output, expected_output)
52
53         version = 0.0
54         expected_output = None
55         output = TOSCAVersionProperty(version).get_version()
56         self.assertEqual(output, expected_output)
57
58         version = 00.00
59         expected_output = None
60         output = TOSCAVersionProperty(version).get_version()
61         self.assertEqual(output, expected_output)
62
63         version = '0.0.0'
64         expected_output = None
65         output = TOSCAVersionProperty(version).get_version()
66         self.assertEqual(output, expected_output)
67
68     def test_tosca_version_property_invalid_major_version(self):
69
70         version = 'x'
71         exp_msg = _('Value of TOSCA version property "x" is invalid.')
72         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
73                                 TOSCAVersionProperty, version)
74         self.assertEqual(exp_msg, err.__str__())
75
76     def test_tosca_version_property_invalid_minor_version(self):
77
78         version = '18.x'
79         exp_msg = _('Value of TOSCA version property "18.x" is invalid.')
80         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
81                                 TOSCAVersionProperty, version)
82         self.assertEqual(exp_msg, err.__str__())
83
84         version = '18.x.y'
85         exp_msg = _('Value of TOSCA version property "18.x.y" is invalid.')
86         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
87                                 TOSCAVersionProperty, version)
88         self.assertEqual(exp_msg, err.__str__())
89
90         version = '18-2'
91         exp_msg = _('Value of TOSCA version property "18-2" is invalid.')
92         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
93                                 TOSCAVersionProperty, version)
94         self.assertEqual(exp_msg, err.__str__())
95
96     def test_tosca_version_property_invalid_fix_version(self):
97
98         version = '18.0.a'
99         exp_msg = _('Value of TOSCA version property "18.0.a" is invalid.')
100         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
101                                 TOSCAVersionProperty, version)
102         self.assertEqual(exp_msg, err.__str__())
103
104     def test_tosca_version_property_invalid_qualifier(self):
105
106         version = '18.0.1-xyz'
107         exp_msg = _('Value of TOSCA version property "18.0.1-xyz" is invalid.')
108         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
109                                 TOSCAVersionProperty, version)
110         self.assertEqual(exp_msg, err.__str__())
111
112         version = '0.0.0.abc'
113         exp_msg = _('Value of TOSCA version property "0.0.0.abc" is invalid.')
114         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
115                                 TOSCAVersionProperty, version)
116         self.assertEqual(exp_msg, err.__str__())
117
118     def test_tosca_version_property_invalid_build_version(self):
119
120         version = '18.0.1.abc-x'
121         exp_msg = _('Value of TOSCA version property '
122                     '"18.0.1.abc-x" is invalid.')
123         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
124                                 TOSCAVersionProperty, version)
125         self.assertEqual(exp_msg, err.__str__())
126
127         version = '0.0.0.abc-x'
128         exp_msg = _('Value of TOSCA version property "0.0.0.abc-x" is '
129                     'invalid.')
130         err = self.assertRaises(InvalidTOSCAVersionPropertyException,
131                                 TOSCAVersionProperty, version)
132         self.assertEqual(exp_msg, err.__str__())