|
18 | 18 | from distutils.version import LooseVersion |
19 | 19 | from f5.bigip.resource import MissingRequiredCreationParameter |
20 | 20 | from f5.bigip.tm.security.firewall import Address_List |
| 21 | +from f5.bigip.tm.security.firewall import Policy |
21 | 22 | from f5.bigip.tm.security.firewall import Port_List |
22 | 23 | from f5.bigip.tm.security.firewall import Rule |
23 | 24 | from f5.bigip.tm.security.firewall import Rule_List |
@@ -63,6 +64,14 @@ def rule(rulelst): |
63 | 64 | r1.delete() |
64 | 65 |
|
65 | 66 |
|
| 67 | +@pytest.fixture(scope='function') |
| 68 | +def policy(mgmt_root): |
| 69 | + p1 = mgmt_root.tm.security.firewall.policy_s.policy.create( |
| 70 | + name='fake_policy', partition='Common') |
| 71 | + yield p1 |
| 72 | + p1.delete() |
| 73 | + |
| 74 | + |
66 | 75 | class TestAddressList(object): |
67 | 76 | def test_create_missing_mandatory_attr_raises(self, mgmt_root): |
68 | 77 | ac = mgmt_root.tm.security.firewall.address_lists |
@@ -477,3 +486,86 @@ def test_rules_subcollection(self, rulelst, rule): |
477 | 486 | assert isinstance(rc, list) |
478 | 487 | assert len(rc) |
479 | 488 | assert isinstance(rc[0], Rule) |
| 489 | + |
| 490 | + |
| 491 | +class TestPolicy(object): |
| 492 | + def test_create_req_args(self, mgmt_root): |
| 493 | + p1 = mgmt_root.tm.security.firewall.policy_s.policy.create( |
| 494 | + name='fake_policy', partition='Common') |
| 495 | + URI = 'https://localhost/mgmt/tm/security/' \ |
| 496 | + 'firewall/policy/~Common~fake_policy' |
| 497 | + assert p1.name == 'fake_policy' |
| 498 | + assert p1.partition == 'Common' |
| 499 | + assert p1.selfLink.startswith(URI) |
| 500 | + assert not hasattr(p1, 'description') |
| 501 | + p1.delete() |
| 502 | + |
| 503 | + def test_refresh(self, mgmt_root, policy): |
| 504 | + p1 = policy |
| 505 | + p2 = mgmt_root.tm.security.firewall.policy_s.policy.load( |
| 506 | + name='fake_policy', partition='Common') |
| 507 | + assert p1.name == p2.name |
| 508 | + assert p1.kind == p2.kind |
| 509 | + assert p1.selfLink == p2.selfLink |
| 510 | + assert not hasattr(p1, 'description') |
| 511 | + assert not hasattr(p2, 'description') |
| 512 | + p2.modify(description=DESC) |
| 513 | + p1.modify(description=DESC) |
| 514 | + assert hasattr(p2, 'description') |
| 515 | + assert p2.description == DESC |
| 516 | + p1.refresh() |
| 517 | + assert p1.selfLink == p2.selfLink |
| 518 | + assert hasattr(p1, 'description') |
| 519 | + assert p1.description == p2.description |
| 520 | + |
| 521 | + def test_delete(self, mgmt_root): |
| 522 | + p = mgmt_root.tm.security.firewall.policy_s.policy |
| 523 | + p1 = p.create(name='delete_me', partition='Common') |
| 524 | + p1.delete() |
| 525 | + with pytest.raises(HTTPError) as err: |
| 526 | + mgmt_root.tm.security.firewall.policy_s.policy.load( |
| 527 | + name='delete_me', partition='Common') |
| 528 | + assert err.value.response.status_code == 404 |
| 529 | + |
| 530 | + def test_load_no_object(self, mgmt_root): |
| 531 | + p = mgmt_root.tm.security.firewall.policy_s.policy |
| 532 | + with pytest.raises(HTTPError) as err: |
| 533 | + p.load(name='not_exists', partition='Common') |
| 534 | + assert err.value.response.status_code == 404 |
| 535 | + |
| 536 | + def test_load_and_update(self, mgmt_root, policy): |
| 537 | + p1 = policy |
| 538 | + URI = 'https://localhost/mgmt/tm/security/' \ |
| 539 | + 'firewall/policy/~Common~fake_policy' |
| 540 | + assert p1.name == 'fake_policy' |
| 541 | + assert p1.partition == 'Common' |
| 542 | + assert p1.selfLink.startswith(URI) |
| 543 | + assert not hasattr(p1, 'description') |
| 544 | + p1.description = DESC |
| 545 | + p1.update() |
| 546 | + assert hasattr(p1, 'description') |
| 547 | + assert p1.description == DESC |
| 548 | + p = mgmt_root.tm.security.firewall.policy_s.policy |
| 549 | + p2 = p.load(name='fake_policy', partition='Common') |
| 550 | + assert p1.name == p2.name |
| 551 | + assert p1.partition == p2.partition |
| 552 | + assert p1.selfLink == p2.selfLink |
| 553 | + assert hasattr(p2, 'description') |
| 554 | + assert p1.description == p2.description |
| 555 | + |
| 556 | + def test_policies_collection(self, mgmt_root, policy): |
| 557 | + pc = mgmt_root.tm.security.firewall.policy_s.get_collection() |
| 558 | + assert isinstance(pc, list) |
| 559 | + assert len(pc) |
| 560 | + assert isinstance(pc[0], Policy) |
| 561 | + |
| 562 | + |
| 563 | +class TestGlobalRules(object): |
| 564 | + def test_modify_req_args(self, mgmt_root, policy): |
| 565 | + rules = mgmt_root.tm.security.firewall. \ |
| 566 | + global_rules.load(partition='Common') |
| 567 | + assert "enforcedPolicy" not in rules.__dict__ |
| 568 | + rules.modify(enforcedPolicy='fake_policy', partition='Common') |
| 569 | + assert rules.enforcedPolicy == "/Common/fake_policy" |
| 570 | + rules.modify(enforcedPolicy='none', partition='Common') |
| 571 | + assert "enforcedPolicy" not in rules.__dict__ |
0 commit comments