# 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
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):
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',
@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.'
@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.'
return_value=True)
@mock.patch('functest.opnfv_tests.openstack.rally.rally.subprocess.Popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.os.makedirs')
- @mock.patch('functest.opnfv_tests.openstack.rally.rally.os.popen')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.info')
@mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.error')
def test_run_task_default(self, mock_logger_error, mock_logger_info,
- mock_popen, *args):
- attrs = {'read.return_value': 'json_result'}
- mock_popen.return_value.configure_mock(**attrs)
+ *args):
self.rally_base._run_task('test_name')
text = 'Test scenario: "test_name" OK.\n'
mock_logger_info.assert_any_call(text)
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)