X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Funit%2Fnetwork_services%2Ftraffic_profile%2Ftest_prox_profile.py;h=078e72b8eee84996e76d48d4846c826435f6e729;hb=5721849f3f08c2c1c89354341115c834e510b3d6;hp=a2ad0333f825fcdd690f8824dfca3d77f7958ca9;hpb=36375f388880519336328406de1d1bbc408d4599;p=yardstick.git diff --git a/tests/unit/network_services/traffic_profile/test_prox_profile.py b/tests/unit/network_services/traffic_profile/test_prox_profile.py index a2ad0333f..078e72b8e 100644 --- a/tests/unit/network_services/traffic_profile/test_prox_profile.py +++ b/tests/unit/network_services/traffic_profile/test_prox_profile.py @@ -14,69 +14,11 @@ # from __future__ import absolute_import -import unittest +import unittest import mock -STL_MOCKS = { - 'stl': mock.MagicMock(), - 'stl.trex_stl_lib': mock.MagicMock(), - 'stl.trex_stl_lib.base64': mock.MagicMock(), - 'stl.trex_stl_lib.binascii': mock.MagicMock(), - 'stl.trex_stl_lib.collections': mock.MagicMock(), - 'stl.trex_stl_lib.copy': mock.MagicMock(), - 'stl.trex_stl_lib.datetime': mock.MagicMock(), - 'stl.trex_stl_lib.functools': mock.MagicMock(), - 'stl.trex_stl_lib.imp': mock.MagicMock(), - 'stl.trex_stl_lib.inspect': mock.MagicMock(), - 'stl.trex_stl_lib.json': mock.MagicMock(), - 'stl.trex_stl_lib.linecache': mock.MagicMock(), - 'stl.trex_stl_lib.math': mock.MagicMock(), - 'stl.trex_stl_lib.os': mock.MagicMock(), - 'stl.trex_stl_lib.platform': mock.MagicMock(), - 'stl.trex_stl_lib.pprint': mock.MagicMock(), - 'stl.trex_stl_lib.random': mock.MagicMock(), - 'stl.trex_stl_lib.re': mock.MagicMock(), - 'stl.trex_stl_lib.scapy': mock.MagicMock(), - 'stl.trex_stl_lib.socket': mock.MagicMock(), - 'stl.trex_stl_lib.string': mock.MagicMock(), - 'stl.trex_stl_lib.struct': mock.MagicMock(), - 'stl.trex_stl_lib.sys': mock.MagicMock(), - 'stl.trex_stl_lib.threading': mock.MagicMock(), - 'stl.trex_stl_lib.time': mock.MagicMock(), - 'stl.trex_stl_lib.traceback': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_async_client': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_client': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_exceptions': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_ext': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_jsonrpc_client': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_packet_builder_interface': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_packet_builder_scapy': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_port': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_stats': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_streams': mock.MagicMock(), - 'stl.trex_stl_lib.trex_stl_types': mock.MagicMock(), - 'stl.trex_stl_lib.types': mock.MagicMock(), - 'stl.trex_stl_lib.utils': mock.MagicMock(), - 'stl.trex_stl_lib.utils.argparse': mock.MagicMock(), - 'stl.trex_stl_lib.utils.collections': mock.MagicMock(), - 'stl.trex_stl_lib.utils.common': mock.MagicMock(), - 'stl.trex_stl_lib.utils.json': mock.MagicMock(), - 'stl.trex_stl_lib.utils.os': mock.MagicMock(), - 'stl.trex_stl_lib.utils.parsing_opts': mock.MagicMock(), - 'stl.trex_stl_lib.utils.pwd': mock.MagicMock(), - 'stl.trex_stl_lib.utils.random': mock.MagicMock(), - 'stl.trex_stl_lib.utils.re': mock.MagicMock(), - 'stl.trex_stl_lib.utils.string': mock.MagicMock(), - 'stl.trex_stl_lib.utils.sys': mock.MagicMock(), - 'stl.trex_stl_lib.utils.text_opts': mock.MagicMock(), - 'stl.trex_stl_lib.utils.text_tables': mock.MagicMock(), - 'stl.trex_stl_lib.utils.texttable': mock.MagicMock(), - 'stl.trex_stl_lib.warnings': mock.MagicMock(), - 'stl.trex_stl_lib.yaml': mock.MagicMock(), - 'stl.trex_stl_lib.zlib': mock.MagicMock(), - 'stl.trex_stl_lib.zmq': mock.MagicMock(), -} +from tests.unit import STL_MOCKS STLClient = mock.MagicMock() stl_patch = mock.patch.dict("sys.modules", STL_MOCKS) @@ -84,6 +26,7 @@ stl_patch.start() if stl_patch: from yardstick.network_services.traffic_profile.prox_profile import ProxProfile + from yardstick.network_services.vnf_generic.vnf.prox_helpers import ProxResourceHelper class TestProxProfile(unittest.TestCase): @@ -120,10 +63,11 @@ class TestProxProfile(unittest.TestCase): } profile = ProxProfile(tp_config) - profile.init(234) - self.assertEqual(profile.queue, 234) + queue = mock.Mock() + profile.init(queue) + self.assertIs(profile.queue, queue) - def test_execute(self): + def test_execute_traffic(self): packet_sizes = [ 10, 100, @@ -136,14 +80,22 @@ class TestProxProfile(unittest.TestCase): } traffic_generator = mock.MagicMock() + + setup_helper = traffic_generator.setup_helper + setup_helper.find_in_section.return_value = None + + prox_resource_helper = ProxResourceHelper(setup_helper) + traffic_generator.resource_helper = prox_resource_helper + profile = ProxProfile(tp_config) self.assertFalse(profile.done) for _ in packet_sizes: with self.assertRaises(NotImplementedError): - profile.execute(traffic_generator) + profile.execute_traffic(traffic_generator) - self.assertIsNone(profile.execute(traffic_generator)) + self.assertIsNone(profile.execute_traffic(traffic_generator)) + self.assertTrue(profile.done) def test_bounds_iterator(self): tp_config = {