|
| 1 | +# Copyright 2015-2016 F5 Networks Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | + |
| 16 | +import copy |
| 17 | +from pprint import pprint as pp |
| 18 | +from six import iteritems |
| 19 | + |
| 20 | + |
| 21 | +TESTDESCRIPTION = "TESTDESCRIPTION" |
| 22 | + |
| 23 | + |
| 24 | +def delete_resource(resources): |
| 25 | + for resource in resources.get_collection(): |
| 26 | + resource.delete() |
| 27 | + |
| 28 | + |
| 29 | +def setup_traffic_test(request, mgmt_root, name, classification): |
| 30 | + def teardown(): |
| 31 | + delete_resource(tc1) |
| 32 | + request.addfinalizer(teardown) |
| 33 | + tc1 = mgmt_root.tm.ltm.traffic_class_s |
| 34 | + pp('****') |
| 35 | + traffic1 = tc1.traffic_class.create(name=name, |
| 36 | + classification=classification) |
| 37 | + return traffic1, tc1 |
| 38 | + |
| 39 | + |
| 40 | +class TestTrafficClass(object): |
| 41 | + def test_trafficclass_create_refresh_update_delete_load( |
| 42 | + self, request, mgmt_root): |
| 43 | + traffic1, tc1 = setup_traffic_test( |
| 44 | + request, mgmt_root, 'fake_traffic1', 'fakeclasstag') |
| 45 | + assert traffic1.name == 'fake_traffic1' |
| 46 | + traffic1.description = TESTDESCRIPTION |
| 47 | + traffic1.update() |
| 48 | + assert traffic1.description == TESTDESCRIPTION |
| 49 | + traffic1.description = '' |
| 50 | + traffic1.refresh() |
| 51 | + assert traffic1.description == TESTDESCRIPTION |
| 52 | + traffic2 = tc1.traffic_class.load(name='fake_traffic1') |
| 53 | + assert traffic2.selfLink == traffic1.selfLink |
| 54 | + |
| 55 | + def test_trafficclass_modify(self, request, mgmt_root): |
| 56 | + traffic1, tc1 = setup_traffic_test( |
| 57 | + request, mgmt_root, 'fake_traffic1', 'fakeclasstag') |
| 58 | + original_dict = copy.copy(traffic1.__dict__) |
| 59 | + desc = 'description' |
| 60 | + traffic1.modify(description='Cool mod test') |
| 61 | + for k, v in iteritems(traffic1.__dict__): |
| 62 | + if k != desc: |
| 63 | + original_dict[k] = traffic1.__dict__[k] |
| 64 | + elif k == desc: |
| 65 | + assert traffic1.__dict__[k] == 'Cool mod test' |
0 commit comments