aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit/odl/test_odl.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2017-01-03 17:36:43 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2017-01-04 15:42:26 +0100
commita7af7049fa6ee0b5d4dadb026c31e3587d8f3b4c (patch)
tree4449ee616edfaa1d113110a122032a640b6e4bcd /functest/tests/unit/odl/test_odl.py
parent1f59d1e080531d333fd0eb4fea0a4714c709da07 (diff)
Fully cover set_robotframework_vars
re.sub() is now tested. Change-Id: I83cf69b66cd1407f5e4439d8c545338c5fb0bde7 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests/unit/odl/test_odl.py')
-rw-r--r--functest/tests/unit/odl/test_odl.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py
index 8d184203..8dcc9bd9 100644
--- a/functest/tests/unit/odl/test_odl.py
+++ b/functest/tests/unit/odl/test_odl.py
@@ -11,6 +11,7 @@ import errno
import logging
import mock
import os
+import StringIO
import unittest
from keystoneauth1.exceptions import auth_plugins
@@ -78,9 +79,39 @@ class ODLTesting(unittest.TestCase):
self.assertFalse(self.test.set_robotframework_vars())
@mock.patch('fileinput.input', return_value=[])
- def test_set_robotframework_vars(self, args):
+ def test_set_robotframework_vars_empty(self, args):
self.assertTrue(self.test.set_robotframework_vars())
+ @mock.patch('sys.stdout', new_callable=StringIO.StringIO)
+ def _test_set_robotframework_vars(self, msg1, msg2, *args):
+ line = mock.MagicMock()
+ line.__iter__.return_value = [msg1]
+ with mock.patch('fileinput.input', return_value=line) as mock_method:
+ self.assertTrue(self.test.set_robotframework_vars())
+ mock_method.assert_called_once_with(
+ os.path.join(odl.ODLTests.odl_test_repo,
+ 'csit/variables/Variables.py'), inplace=True)
+ self.assertEqual(args[0].getvalue(), "{}\n".format(msg2))
+
+ def test_set_robotframework_vars_auth_default(self):
+ self._test_set_robotframework_vars("AUTH = []",
+ "AUTH = [u'admin', u'admin']")
+
+ def test_set_robotframework_vars_auth1(self):
+ self._test_set_robotframework_vars("AUTH1 = []", "AUTH1 = []")
+
+ @mock.patch('sys.stdout', new_callable=StringIO.StringIO)
+ def test_set_robotframework_vars_auth_foo(self, *args):
+ line = mock.MagicMock()
+ line.__iter__.return_value = ["AUTH = []"]
+ with mock.patch('fileinput.input', return_value=line) as mock_method:
+ self.assertTrue(self.test.set_robotframework_vars('foo', 'bar'))
+ mock_method.assert_called_once_with(
+ os.path.join(odl.ODLTests.odl_test_repo,
+ 'csit/variables/Variables.py'), inplace=True)
+ self.assertEqual(args[0].getvalue(),
+ "AUTH = [u'{}', u'{}']\n".format('foo', 'bar'))
+
@classmethod
def _fake_url_for(cls, service_type='identity', **kwargs):
if service_type == 'identity':