|
| 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 | +from f5.bigip import ManagementRoot |
| 17 | +from f5.bigip.resource import OrganizingCollection |
| 18 | +from f5.bigip.tm.analytics.protocol_inspection import Generate_Report |
| 19 | +from f5.bigip.tm.analytics.protocol_inspection import Report_Results |
| 20 | +from f5.sdk_exception import MissingRequiredCreationParameter |
| 21 | +from f5.sdk_exception import UnsupportedOperation |
| 22 | + |
| 23 | + |
| 24 | +import mock |
| 25 | +import pytest |
| 26 | +from six import iterkeys |
| 27 | + |
| 28 | + |
| 29 | +@pytest.fixture |
| 30 | +def FakeGenerateReport(): |
| 31 | + fake_analytics = mock.MagicMock() |
| 32 | + fake_genrep = Generate_Report(fake_analytics) |
| 33 | + fake_genrep._meta_data['bigip'].tmos_version = '13.1.0' |
| 34 | + return fake_genrep |
| 35 | + |
| 36 | + |
| 37 | +@pytest.fixture |
| 38 | +def FakeReportResults(): |
| 39 | + fake_analytics = mock.MagicMock() |
| 40 | + fake_repres = Report_Results(fake_analytics) |
| 41 | + return fake_repres |
| 42 | + |
| 43 | + |
| 44 | +class TestProtocolInspection(object): |
| 45 | + def test_collection(self, fakeicontrolsession): |
| 46 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 47 | + t1 = b.tm.analytics.protocol_inspection |
| 48 | + assert isinstance(t1, OrganizingCollection) |
| 49 | + assert hasattr(t1, 'generate_reports') |
| 50 | + assert hasattr(t1, 'report_results_s') |
| 51 | + |
| 52 | + |
| 53 | +class TestGenerateReport(object): |
| 54 | + def test_modify_raises(self, FakeGenerateReport): |
| 55 | + with pytest.raises(UnsupportedOperation): |
| 56 | + FakeGenerateReport.modify() |
| 57 | + |
| 58 | + def test_create_no_args(self, FakeGenerateReport): |
| 59 | + with pytest.raises(MissingRequiredCreationParameter): |
| 60 | + FakeGenerateReport.create() |
| 61 | + |
| 62 | + def test_create_two(self, fakeicontrolsession): |
| 63 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 64 | + t1 = b.tm.analytics.protocol_inspection.generate_reports.generate_report |
| 65 | + t2 = b.tm.analytics.protocol_inspection.generate_reports.generate_report |
| 66 | + assert t1 is t2 |
| 67 | + |
| 68 | + def test_collection(self, fakeicontrolsession): |
| 69 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 70 | + t = b.tm.analytics.protocol_inspection.generate_reports |
| 71 | + test_meta = t._meta_data['attribute_registry'] |
| 72 | + test_meta2 = t._meta_data['allowed_lazy_attributes'] |
| 73 | + kind = 'tm:analytics:protocol-inspection:generate-report:avrgeneratereporttaskitemstate' |
| 74 | + assert kind in list(iterkeys(test_meta)) |
| 75 | + assert Generate_Report in test_meta2 |
| 76 | + assert t._meta_data['object_has_stats'] is False |
| 77 | + |
| 78 | + |
| 79 | +class TestReportResults(object): |
| 80 | + def test_create_raises(self, FakeReportResults): |
| 81 | + with pytest.raises(UnsupportedOperation): |
| 82 | + FakeReportResults.create() |
| 83 | + |
| 84 | + def test_modify_raises(self, FakeReportResults): |
| 85 | + with pytest.raises(UnsupportedOperation): |
| 86 | + FakeReportResults.modify() |
| 87 | + |
| 88 | + def test_collection(self, fakeicontrolsession): |
| 89 | + b = ManagementRoot('192.168.1.1', 'admin', 'admin') |
| 90 | + t = b.tm.analytics.protocol_inspection.report_results_s |
| 91 | + test_meta = t._meta_data['attribute_registry'] |
| 92 | + test_meta2 = t._meta_data['allowed_lazy_attributes'] |
| 93 | + kind = 'tm:analytics:protocol-inspection:report-results:avrreportresultitemstate' |
| 94 | + assert kind in list(iterkeys(test_meta)) |
| 95 | + assert Report_Results in test_meta2 |
| 96 | + assert t._meta_data['object_has_stats'] is False |
0 commit comments