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
5 # http://www.apache.org/licenses/LICENSE-2.0
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
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
20 class TOSCAVersionPropertyTest(TestCase):
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)
29 expected_output = '18.0'
30 output = TOSCAVersionProperty(version).get_version()
31 self.assertEqual(output, expected_output)
34 expected_output = '18.0'
35 output = TOSCAVersionProperty(version).get_version()
36 self.assertEqual(output, expected_output)
39 expected_output = '18.0.3'
40 output = TOSCAVersionProperty(version).get_version()
41 self.assertEqual(output, expected_output)
44 expected_output = None
45 output = TOSCAVersionProperty(version).get_version()
46 self.assertEqual(output, expected_output)
49 expected_output = None
50 output = TOSCAVersionProperty(version).get_version()
51 self.assertEqual(output, expected_output)
54 expected_output = None
55 output = TOSCAVersionProperty(version).get_version()
56 self.assertEqual(output, expected_output)
59 expected_output = None
60 output = TOSCAVersionProperty(version).get_version()
61 self.assertEqual(output, expected_output)
64 expected_output = None
65 output = TOSCAVersionProperty(version).get_version()
66 self.assertEqual(output, expected_output)
68 def test_tosca_version_property_invalid_major_version(self):
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__())
76 def test_tosca_version_property_invalid_minor_version(self):
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__())
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__())
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__())
96 def test_tosca_version_property_invalid_fix_version(self):
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__())
104 def test_tosca_version_property_invalid_qualifier(self):
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__())
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__())
118 def test_tosca_version_property_invalid_build_version(self):
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__())
127 version = '0.0.0.abc-x'
128 exp_msg = _('Value of TOSCA version property "0.0.0.abc-x" is '
130 err = self.assertRaises(InvalidTOSCAVersionPropertyException,
131 TOSCAVersionProperty, version)
132 self.assertEqual(exp_msg, err.__str__())