|
| 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 | + |
| 17 | +import mock |
| 18 | +import pytest |
| 19 | + |
| 20 | +from f5.bigip.tm.sys.cluster import Cluster |
| 21 | +from f5.bigip.tm.sys.cluster import Default |
| 22 | +from f5.sdk_exception import InvalidResource |
| 23 | +from f5.sdk_exception import UnsupportedMethod |
| 24 | + |
| 25 | + |
| 26 | +@pytest.fixture |
| 27 | +def FakeCluster(): |
| 28 | + fake_sys = mock.MagicMock() |
| 29 | + return Cluster(fake_sys) |
| 30 | + |
| 31 | + |
| 32 | +@pytest.fixture |
| 33 | +def FakeClusterDefault(): |
| 34 | + fake_sys = mock.MagicMock() |
| 35 | + return Default(fake_sys) |
| 36 | + |
| 37 | + |
| 38 | +def test_create_raises(FakeCluster): |
| 39 | + with pytest.raises(InvalidResource) as EIO: |
| 40 | + FakeCluster.create() |
| 41 | + assert str(EIO.value) == "Only Resources support 'create'." |
| 42 | + |
| 43 | + |
| 44 | +def test_delete_raises(FakeCluster): |
| 45 | + with pytest.raises(InvalidResource) as EIO: |
| 46 | + FakeCluster.delete() |
| 47 | + assert str(EIO.value) == "Only Resources support 'delete'." |
| 48 | + |
| 49 | + |
| 50 | +def test_default_create_raises(FakeClusterDefault): |
| 51 | + with pytest.raises(UnsupportedMethod) as EIO: |
| 52 | + FakeClusterDefault.create() |
| 53 | + assert str(EIO.value) == "Default does not support the create method" |
| 54 | + |
| 55 | + |
| 56 | +def test_default_delete_raises(FakeClusterDefault): |
| 57 | + with pytest.raises(UnsupportedMethod) as EIO: |
| 58 | + FakeClusterDefault.delete() |
| 59 | + assert str(EIO.value) == "Default does not support the delete method" |
0 commit comments