Skip to content

Commit b6681b3

Browse files
Cipher unit test
(cherry picked from commit c3a799c)
1 parent 5c7ec74 commit b6681b3

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# Copyright 2021 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_cipher_rule_test(request, mgmt_root, name, partition, maxRate):
31+
def teardown():
32+
delete_resource(rule)
33+
request.addfinalizer(teardown)
34+
35+
rule = mgmt_root.tm.ltm.cipher.rules.rule.create(
36+
name=name, partition=partition, maxRate=maxRate)
37+
return rule
38+
39+
40+
def setup_cipher_group_test(request, mgmt_root, name, partition, maxRate):
41+
def teardown():
42+
delete_resource(group)
43+
request.addfinalizer(teardown)
44+
45+
group = mgmt_root.tm.ltm.cipher.groups.group.create(
46+
name=name, partition=partition, maxRate=maxRate)
47+
return group
48+
49+
50+
class TestCipherRules(object):
51+
def test_cipher_rule_list(self, mgmt_root):
52+
rules = mgmt_root.tm.ltm.cipher.rules.get_collection()
53+
assert len(rules)
54+
for rule in rules:
55+
assert rule.generation
56+
57+
58+
class TestCipherRule(object):
59+
def test_cipher_rule_CURDL(self, request, mgmt_root):
60+
# Create and Delete are tested by the setup/teardown
61+
r1 = setup_cipher_rule_test(
62+
request, mgmt_root, 'cipher-rule-test', 'Common', 1000000
63+
)
64+
65+
# Load
66+
r2 = mgmt_root.tm.ltm.cipher.rules.rule.load(
67+
name='cipher-rule-test', partition='Common')
68+
assert r1.name == 'cipher-rule-test'
69+
assert r1.name == r2.name
70+
assert r1.generation == r2.generation
71+
72+
# Update
73+
r1.description = TEST_DESCR
74+
r1.update()
75+
assert r1.description == TEST_DESCR
76+
assert r1.generation > r2.generation
77+
78+
# Refresh
79+
r2.refresh()
80+
assert r2.description == TEST_DESCR
81+
assert r1.generation == r2.generation
82+
83+
84+
class TestCipherGroups(object):
85+
def test_cipher_group_list(self, mgmt_root):
86+
groups = mgmt_root.tm.ltm.cipher.groups.get_collection()
87+
assert len(groups)
88+
for group in groups:
89+
assert group.generation
90+
91+
92+
class TestCipherGroup(object):
93+
def test_cipher_group_CURDL(self, request, mgmt_root):
94+
# Create and Delete are tested by the setup/teardown
95+
g1 = setup_cipher_group_test(
96+
request, mgmt_root, 'cipher-group-test', 'Common', 1000000
97+
)
98+
99+
# Load
100+
g2 = mgmt_root.tm.ltm.cipher.groups.group.load(
101+
name='cipher-group-test', partition='Common')
102+
assert g1.name == 'cipher-group-test'
103+
assert g1.name == g2.name
104+
assert g1.generation == g2.generation
105+
106+
# Update
107+
g1.description = TEST_DESCR
108+
g1.update()
109+
assert g1.description == TEST_DESCR
110+
assert g1.generation > g2.generation
111+
112+
# Refresh
113+
g2.refresh()
114+
assert g2.description == TEST_DESCR
115+
assert g1.generation == g2.generation
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2021 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 mock
17+
import pytest
18+
19+
from f5.bigip import ManagementRoot
20+
from f5.bigip.tm.ltm.cipher import Group
21+
from f5.bigip.tm.ltm.cipher import Rule
22+
from f5.sdk_exception import MissingRequiredCreationParameter
23+
24+
25+
@pytest.fixture
26+
def FakeCipherRule():
27+
fake_rule_s = mock.MagicMock()
28+
fake_rule = Rule(fake_rule_s)
29+
return fake_rule
30+
31+
32+
@pytest.fixture
33+
def FakeCipherGroup():
34+
fake_group_s = mock.MagicMock()
35+
fake_group = Group(fake_group_s)
36+
return fake_group
37+
38+
39+
class TestCipherRuleCreate(object):
40+
def test_create_two(self, fakeicontrolsession):
41+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
42+
r1 = b.tm.ltm.cipher.rules.rule
43+
r2 = b.tm.ltm.cipher.rules.rule
44+
assert r1 is not r2
45+
46+
def test_create_no_args(self, FakeCipherRule):
47+
with pytest.raises(MissingRequiredCreationParameter):
48+
FakeCipherRule.create()
49+
50+
51+
class TestCipherGroupCreate(object):
52+
def test_create_two(self, fakeicontrolsession):
53+
b = ManagementRoot('192.168.1.1', 'admin', 'admin')
54+
g1 = b.tm.ltm.cipher.groups.group
55+
g2 = b.tm.ltm.cipher.groups.group
56+
assert g1 is not g2
57+
58+
def test_create_no_args(self, FakeCipherGroup):
59+
with pytest.raises(MissingRequiredCreationParameter):
60+
FakeCipherGroup.create()

0 commit comments

Comments
 (0)