|
| 1 | +# Copyright 2020 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 | +from requests.exceptions import HTTPError |
| 17 | + |
| 18 | + |
| 19 | +TEST_DESCR = "TEST DESCRIPTION" |
| 20 | + |
| 21 | + |
| 22 | +def delete_resource(resource): |
| 23 | + try: |
| 24 | + resource.delete() |
| 25 | + except HTTPError as err: |
| 26 | + if err.response.status_code != 404: |
| 27 | + raise |
| 28 | + |
| 29 | + |
| 30 | +def setup_policy_test(request, mgmt_root, name, partition, maxRate): |
| 31 | + def teardown(): |
| 32 | + delete_resource(policy) |
| 33 | + request.addfinalizer(teardown) |
| 34 | + |
| 35 | + policy = mgmt_root.tm.net.bwc.policys.policy.create( |
| 36 | + name=name, partition=partition, maxRate=maxRate) |
| 37 | + return policy |
| 38 | + |
| 39 | + |
| 40 | +class TestPolicys(object): |
| 41 | + def test_policy_list(self, mgmt_root): |
| 42 | + policies = mgmt_root.tm.net.bwc.policys.get_collection() |
| 43 | + assert len(policies) |
| 44 | + for policy in policies: |
| 45 | + assert policy.generation |
| 46 | + |
| 47 | + |
| 48 | +class TestPolicy(object): |
| 49 | + def test_policy_CURDL(self, request, mgmt_root): |
| 50 | + # Create and Delete are tested by the setup/teardown |
| 51 | + p1 = setup_policy_test( |
| 52 | + request, mgmt_root, 'bwc-policy-test', 'Common', 1000000 |
| 53 | + ) |
| 54 | + |
| 55 | + # Load |
| 56 | + p2 = mgmt_root.tm.net.bwc.policys.policy.load( |
| 57 | + name='bwc-policy-test', partition='Common') |
| 58 | + assert p1.name == 'bwc-policy-test' |
| 59 | + assert p1.name == p2.name |
| 60 | + assert p1.generation == p2.generation |
| 61 | + |
| 62 | + # Update |
| 63 | + p1.description = TEST_DESCR |
| 64 | + p1.update() |
| 65 | + assert p1.description == TEST_DESCR |
| 66 | + assert p1.generation > p2.generation |
| 67 | + |
| 68 | + # Refresh |
| 69 | + p2.refresh() |
| 70 | + assert p2.description == TEST_DESCR |
| 71 | + assert p1.generation == p2.generation |
0 commit comments