3 # Copyright (c) 2018 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # pylint: disable=missing-docstring
16 from six.moves import reload_module
18 from functest.utils import env
19 from functest.utils import constants
22 class EnvTesting(unittest.TestCase):
23 # pylint: disable=missing-docstring
26 os.environ['FOO'] = 'foo'
27 os.environ['BUILD_TAG'] = 'master'
28 os.environ['CI_LOOP'] = 'weekly'
30 def test_get_unset_unknown_env(self):
32 self.assertEqual(env.get('FOO'), None)
33 # Backward compatibilty (waiting for SDNVPN and SFC)
35 with self.assertRaises(AttributeError):
36 getattr(env.ENV, 'FOO')
37 reload_module(constants)
38 with self.assertRaises(AttributeError):
39 getattr(constants.CONST, 'FOO')
41 def test_get_unknown_env(self):
42 self.assertEqual(env.get('FOO'), 'foo')
44 # Backward compatibilty (waiting for SDNVPN and SFC)
45 with self.assertRaises(AttributeError):
46 getattr(env.ENV, 'FOO')
47 reload_module(constants)
48 with self.assertRaises(AttributeError):
49 getattr(constants.CONST, 'FOO')
51 def test_get_unset_env(self):
52 del os.environ['CI_LOOP']
54 env.get('CI_LOOP'), env.INPUTS['CI_LOOP'])
55 # Backward compatibilty (waiting for SDNVPN and SFC)
58 getattr(env.ENV, 'CI_LOOP'), env.INPUTS['CI_LOOP'])
59 reload_module(constants)
61 getattr(constants.CONST, 'CI_LOOP'),
62 env.INPUTS['CI_LOOP'])
64 def test_get_env(self):
66 env.get('CI_LOOP'), 'weekly')
67 # Backward compatibilty (waiting for SDNVPN and SFC)
69 self.assertEqual(getattr(env.ENV, 'CI_LOOP'), 'weekly')
70 reload_module(constants)
71 self.assertEqual(getattr(constants.CONST, 'CI_LOOP'), 'weekly')
73 def test_get_unset_env2(self):
74 del os.environ['BUILD_TAG']
76 env.get('BUILD_TAG'), env.INPUTS['BUILD_TAG'])
77 # Backward compatibilty (waiting for SDNVPN and SFC)
80 getattr(env.ENV, 'BUILD_TAG'), env.INPUTS['BUILD_TAG'])
81 reload_module(constants)
83 getattr(constants.CONST, 'BUILD_TAG'), env.INPUTS['BUILD_TAG'])
85 def test_get_env2(self):
86 self.assertEqual(env.get('BUILD_TAG'), 'master')
87 # Backward compatibilty (waiting for SDNVPN and SFC)
89 self.assertEqual(getattr(env.ENV, 'BUILD_TAG'), 'master')
91 self.assertEqual(getattr(constants.CONST, 'BUILD_TAG'), 'master')
94 if __name__ == "__main__":
95 logging.disable(logging.CRITICAL)
96 unittest.main(verbosity=2)