|
| 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 pytest |
| 17 | + |
| 18 | +from distutils.version import LooseVersion |
| 19 | +from requests.exceptions import HTTPError |
| 20 | + |
| 21 | + |
| 22 | +@pytest.fixture(scope='function') |
| 23 | +def nameserver(mgmt_root): |
| 24 | + resource = mgmt_root.tm.ltm.dns.nameservers.nameserver.create( |
| 25 | + name='ns1', |
| 26 | + address='1.1.1.1', |
| 27 | + port=53 |
| 28 | + ) |
| 29 | + yield resource |
| 30 | + resource.delete() |
| 31 | + |
| 32 | + |
| 33 | +@pytest.mark.skipif( |
| 34 | + LooseVersion(pytest.config.getoption('--release')) < LooseVersion('12.0.0'), |
| 35 | + reason='This collection is fully implemented on 12.0.0 or greater.' |
| 36 | +) |
| 37 | +class TestAuditLogs(object): |
| 38 | + def test_update_refresh(self, nameserver): |
| 39 | + assert nameserver.kind == 'tm:ltm:dns:nameserver:nameserverstate' |
| 40 | + assert nameserver.port == 53 |
| 41 | + nameserver.update(port=1234) |
| 42 | + nameserver.refresh() |
| 43 | + assert nameserver.port == 1234 |
| 44 | + |
| 45 | + def test_load_no_object(self, mgmt_root): |
| 46 | + with pytest.raises(HTTPError) as err: |
| 47 | + mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='not-found') |
| 48 | + assert err.value.response.status_code == 404 |
| 49 | + |
| 50 | + def test_load(self, nameserver, mgmt_root): |
| 51 | + r1 = mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='ns1') |
| 52 | + assert r1.kind == 'tm:ltm:dns:nameserver:nameserverstate' |
| 53 | + r2 = mgmt_root.tm.ltm.dns.nameservers.nameserver.load(name='ns1') |
| 54 | + assert r1.kind == r2.kind |
| 55 | + assert r1.selfLink == r2.selfLink |
| 56 | + |
| 57 | + def test_collection(self, nameserver, mgmt_root): |
| 58 | + collection = mgmt_root.tm.ltm.dns.nameservers.get_collection() |
| 59 | + assert len(collection) == 1 |
0 commit comments