Remove duplicated code related to snaps creds
[functest.git] / functest / tests / unit / openstack / rally / test_rally.py
index 450eb85..92177f3 100644 (file)
@@ -5,6 +5,8 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 
+# pylint: disable=missing-docstring
+
 import json
 import logging
 import os
@@ -24,10 +26,9 @@ class OSRallyTesting(unittest.TestCase):
         os_creds = OSCreds(
             username='user', password='pass',
             auth_url='http://foo.com:5000/v3', project_name='bar')
-        with mock.patch('snaps.openstack.tests.openstack_tests.'
+        with mock.patch('functest.opnfv_tests.openstack.snaps.snaps_utils.'
                         'get_credentials', return_value=os_creds) as m:
             self.rally_base = rally.RallyBase()
-            self.polling_iter = 2
         self.assertTrue(m.called)
 
     def test_build_task_args_missing_floating_network(self):
@@ -102,19 +103,11 @@ class OSRallyTesting(unittest.TestCase):
         self.assertEqual(self.rally_base.task_succeed(json_raw),
                          True)
 
-    def polling(self):
-        if self.polling_iter == 0:
-            return "something"
-        self.polling_iter -= 1
-        return None
-
     def test_get_cmd_output(self):
         proc = mock.Mock()
-        attrs = {'poll.side_effect': self.polling,
-                 'stdout.readline.return_value': 'line'}
-        proc.configure_mock(**attrs)
+        proc.stdout.__iter__ = mock.Mock(return_value=iter(['line1', 'line2']))
         self.assertEqual(self.rally_base.get_cmd_output(proc),
-                         'lineline')
+                         'line1line2')
 
     @mock.patch('__builtin__.open', mock.mock_open())
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.yaml.safe_load',
@@ -227,7 +220,7 @@ class OSRallyTesting(unittest.TestCase):
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 '_build_task_args', return_value={})
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
-                '_get_output')
+                '_append_summary')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 'get_task_id', return_value=None)
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -249,7 +242,7 @@ class OSRallyTesting(unittest.TestCase):
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 '_build_task_args', return_value={})
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
-                '_get_output')
+                '_append_summary')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
                 'get_task_id', return_value='1')
     @mock.patch('functest.opnfv_tests.openstack.rally.rally.RallyBase.'
@@ -431,6 +424,16 @@ class OSRallyTesting(unittest.TestCase):
         self.assertEqual(self.rally_base.run(), testcase.TestCase.EX_RUN_ERROR)
         mock_prep_env.assert_called()
 
+    def test_append_summary(self):
+        text = '[{"result":[{"error":[]},{"error":["err"]}],' \
+               '"full_duration": 17.312026}]'
+        self.rally_base._append_summary(text, "foo_test")
+        self.assertEqual(self.rally_base.summary[0]['test_name'], "foo_test")
+        self.assertEqual(self.rally_base.summary[0]['overall_duration'],
+                         17.312026)
+        self.assertEqual(self.rally_base.summary[0]['nb_tests'], 2)
+        self.assertEqual(self.rally_base.summary[0]['nb_success'], 1)
+
 
 if __name__ == "__main__":
     logging.disable(logging.CRITICAL)