aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/network_services/traffic_profile/test_base.py
blob: 2906103614c801b135ddce7fd5dd1321fa3db1b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python

# Copyright (c) 2016-2017 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Unittest for yardstick.network_services.traffic_profile.test_base

from __future__ import absolute_import
import unittest
import mock

from yardstick.network_services.traffic_profile.base import \
    TrafficProfile, DummyProfile


class TestTrafficProfile(unittest.TestCase):
    TRAFFIC_PROFILE = {
        "schema": "isb:traffic_profile:0.1",
        "name": "fixed",
        "description": "Fixed traffic profile to run UDP traffic",
        "traffic_profile": {
            "traffic_type": "FixedTraffic",
            "frame_rate": 100,  # pps
            "flow_number": 10,
            "frame_size": 64}}

    def _get_res_mock(self, **kw):
        _mock = mock.MagicMock()
        for k, v in kw.items():
            setattr(_mock, k, v)
            return _mock

    def test___init__(self):
        traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
        self.assertEqual(self.TRAFFIC_PROFILE, traffic_profile.params)

    def test_execute(self):
        traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
        self.assertRaises(NotImplementedError, traffic_profile.execute_traffic, {})

    def test_get(self):
        traffic_profile = TrafficProfile(self.TRAFFIC_PROFILE)
        self.assertRaises(RuntimeError, traffic_profile.get,
                          self.TRAFFIC_PROFILE)


class TestDummyProfile(unittest.TestCase):
    def test_execute(self):
        dummy_profile = DummyProfile(TrafficProfile)
        self.assertIsNone(dummy_profile.execute({}))