|
| 1 | +# Copyright 2018 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 os |
| 17 | +import pytest |
| 18 | +import tempfile |
| 19 | + |
| 20 | +from distutils.version import LooseVersion |
| 21 | + |
| 22 | + |
| 23 | +pytestmark = pytest.mark.skipif( |
| 24 | + LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.0.0'), |
| 25 | + reason='This series of tests requires BIG-IP version 12.0.0 or greater.' |
| 26 | +) |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def timer_policy(mgmt_root): |
| 31 | + file = tempfile.NamedTemporaryFile() |
| 32 | + name = os.path.basename(file.name) |
| 33 | + resource = mgmt_root.tm.net.timer_policys.timer_policy.create( |
| 34 | + name=name |
| 35 | + ) |
| 36 | + yield resource |
| 37 | + resource.delete() |
| 38 | + |
| 39 | + |
| 40 | +@pytest.fixture |
| 41 | +def service_policy_with_timer_policy(mgmt_root, timer_policy): |
| 42 | + file = tempfile.NamedTemporaryFile() |
| 43 | + name = os.path.basename(file.name) |
| 44 | + resource = mgmt_root.tm.net.service_policys.service_policy.create( |
| 45 | + name=name, |
| 46 | + timerPolicy=timer_policy.name |
| 47 | + ) |
| 48 | + yield resource |
| 49 | + resource.delete() |
| 50 | + |
| 51 | + |
| 52 | +@pytest.fixture |
| 53 | +def service_policy(mgmt_root): |
| 54 | + file = tempfile.NamedTemporaryFile() |
| 55 | + name = os.path.basename(file.name) |
| 56 | + resource = mgmt_root.tm.net.service_policys.service_policy.create( |
| 57 | + name=name |
| 58 | + ) |
| 59 | + yield resource |
| 60 | + resource.delete() |
| 61 | + |
| 62 | + |
| 63 | +@pytest.fixture |
| 64 | +def service_policies(mgmt_root): |
| 65 | + collection = mgmt_root.tm.net.service_policys |
| 66 | + return collection |
| 67 | + |
| 68 | + |
| 69 | +class TestResource(object): |
| 70 | + def test_get_collection(self, service_policy, service_policies): |
| 71 | + assert len(list(service_policies.get_collection())) > 0 |
| 72 | + |
| 73 | + def test_create(self, mgmt_root): |
| 74 | + file = tempfile.NamedTemporaryFile() |
| 75 | + name = os.path.basename(file.name) |
| 76 | + resource = mgmt_root.tm.net.service_policys.service_policy.create( |
| 77 | + name=name |
| 78 | + ) |
| 79 | + assert resource.name == name |
| 80 | + resource.delete() |
| 81 | + |
| 82 | + def test_update(self, timer_policy, service_policy): |
| 83 | + service_policy.description = 'my description' |
| 84 | + service_policy.timerPolicy = timer_policy.name |
| 85 | + service_policy.update() |
| 86 | + assert service_policy.description == 'my description' |
| 87 | + assert service_policy.timerPolicy == '/Common/{0}'.format(timer_policy.name) |
| 88 | + |
| 89 | + def test_refresh(self, service_policy): |
| 90 | + assert not hasattr(service_policy, 'description') |
| 91 | + service_policy.description = 'disabled' |
| 92 | + |
| 93 | + # A refresh without an update should show no change |
| 94 | + service_policy.refresh() |
| 95 | + assert not hasattr(service_policy, 'description') |
0 commit comments