Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_ACPRule_source_network_add_for_literals_and_objects_present_initially(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.sourceNetworks = {
"objects": [
{
"name": "someExistingObjectName3",
"id": "someExistingObjectId3",
"type": "someExistingObjectType3",
},
{
"name": "someExistingObjectName1",
"id": "someExistingObjectId1",
"type": "someExistingObjectType1",
},
],
"literals": {},
}
rule_obj.URL = "/accesspolicies//accessrules/"
def test_ACPRule_source_network_remove_for_objects_with_multiple_objects_present(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.sourceNetworks = {
"objects": [
{
"name": "someExistingObjectName1",
"id": "someExistingObjectId1",
"type": "someExistingObjectType1",
},
{
"name": "someExistingObjectName2",
"id": "someExistingObjectId2",
"type": "someExistingObjectType2",
},
{
"name": "someExistingObjectName3",
"id": "someExistingObjectId3",
"type": "someExistingObjectType3",
},
{
"name": "someExistingObjectName2",
"id": "someExistingObjectId2",
"type": "someExistingObjectType2",
},
{
"name": "someExistingObjectName3",
"id": "someExistingObjectId3",
"type": "someExistingObjectType3",
},
]
mock_ipaddress.return_value = value
mock_nwgroup.return_value = dummyvalue3
mock_fqdns.return_value = dummyvalue3
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.sourceNetworks = {
"objects": [
{
"name": "someExistingObjectName3",
"id": "someExistingObjectId3",
"type": "someExistingObjectType3",
}
]
}
rule_obj.URL = "/accesspolicies//accessrules/"
rule_obj.source_network(action="add", name="someExistingObjectName2")
self.assertEqual(len(rule_obj.sourceNetworks["objects"]), 2)
self.assertEqual(
rule_obj.sourceNetworks["objects"][0],
{
"name": "someExistingObjectName3",
def test_ACPRule_source_network_remove_for_literals_with_only_one_literal_present(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.sourceNetworks = {"literals": {"10.0.0.1": "host"}}
rule_obj.source_network(action="remove", literal="10.0.0.1")
self.assertEqual(len(rule_obj.sourceNetworks["literals"]), 0)
def test_URL_SUFFIX_6(self, mock_fmc, *_):
"""
Test URL_SUFFIX property
- Category param
- insertAfter param
"""
a = api_objects.AccessRules(
fmc=mock_fmc,
acp_name="something",
category="something",
insertAfter="something",
)
self.assertTrue(a.URL.endswith("?category=something&insertAfter=something"))
def test_ACPRule_destination_network_add_for_literals_and_duplicate_literal_present(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.destinationNetworks = {"literals": {"10.0.0.1": "host"}}
rule_obj.URL = "/accesspolicies//accessrules/"
rule_obj.destination_network(action="add", literal="10.0.0.1")
self.assertEqual(len(rule_obj.destinationNetworks["literals"]), 1)
def test_ACPRule_source_network_add_for_literals_and_no_literal_present_initially(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.URL = "/accesspolicies//accessrules/"
rule_obj.source_network(action="add", literal="10.0.0.1")
self.assertEqual(len(rule_obj.sourceNetworks["literals"]), 1)
self.assertEqual(rule_obj.sourceNetworks["literals"]["10.0.0.1"], "host")
def test_URL_SUFFIX_4(self, mock_fmc, *_):
"""
Test URL_SUFFIX property
- insertAfter param
"""
a = api_objects.AccessRules(
fmc=mock_fmc, acp_name="something", insertAfter="something"
)
self.assertTrue(a.URL.endswith("?insertAfter=something"))
{
"name": "someExistingObjectName2",
"id": "someExistingObjectId2",
"type": "someExistingObjectType2",
},
{
"name": "someExistingObjectName3",
"id": "someExistingObjectId3",
"type": "someExistingObjectType3",
},
]
mock_ipaddress.return_value = value
mock_nwgroup.return_value = dummyvalue3
mock_fqdns.return_value = dummyvalue3
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.URL = "/accesspolicies//accessrules/"
rule_obj.source_network(action="add", name="someExistingObjectName2")
self.assertEqual(len(rule_obj.sourceNetworks["objects"]), 1)
self.assertEqual(
rule_obj.sourceNetworks,
{
"objects": [
{
"name": "someExistingObjectName2",
"id": "someExistingObjectId2",
"type": "someExistingObjectType2",
}
def test_ACPRule_source_network_add_for_literals_and_multiple_literal_present_initially(
self, _
):
rule_obj = api_objects.AccessRules(fmc=mock.Mock())
rule_obj.sourceNetworks = {
"literals": {"10.0.0.1": "host", "10.0.0.2": "host", "10.0.0.3": "host"}
}
rule_obj.URL = "/accesspolicies//accessrules/"
rule_obj.source_network(action="add", literal="10.0.0.4")
self.assertEqual(len(rule_obj.sourceNetworks["literals"]), 4)
self.assertEqual(rule_obj.sourceNetworks["literals"]["10.0.0.1"], "host")
self.assertEqual(rule_obj.sourceNetworks["literals"]["10.0.0.2"], "host")
self.assertEqual(rule_obj.sourceNetworks["literals"]["10.0.0.3"], "host")
self.assertEqual(rule_obj.sourceNetworks["literals"]["10.0.0.4"], "host")