def test_are_dicts_equal_when_source_has_more_keys():
    s = {"key1": "val1"}
    t = {}
    assert oci_common_utils.are_dicts_equal(s, t) is False
    assert (oci_common_utils.is_dict_subset(
        s, t, ignore_attr_if_not_in_target=True) is True)

    s = {"key1": "val1", "key2": "val2"}
    t = {"key1": "val1"}
    assert oci_common_utils.are_dicts_equal(s, t) is False
    assert (oci_common_utils.is_dict_subset(
        s, t, ignore_attr_if_not_in_target=True) is True)

    s = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    t = {"key1": "val1", "key2": {"subkey1": "subval1"}}
    assert oci_common_utils.are_dicts_equal(s, t) is False

    s = {
        "key1": "val1",
        "key2": {
            "subkey1": "subval1",
            "subkey3": "subval3"
        },
        "key3": "val3",
    }
    t = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    assert oci_common_utils.are_dicts_equal(s, t) is False
def test_is_dict_subset_when_dicts_have_list_values():
    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item2", "item3"]}
    assert oci_common_utils.is_dict_subset(s, t) is False

    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item2", "item3", "item1"]}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item1", "item2", "item3", "item4"]}
    assert oci_common_utils.is_dict_subset(s, t) is False
def test_is_dict_subset_when_source_has_less_keys():
    s = {"key1": "val1"}
    t = {"key1": "val1", "key2": "val2"}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {"key1": "val1"}
    t = {"key1": "val1", "key2": "val2", "key3": "val3"}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {}
    t = {"key1": "val1", "key2": "val2"}
    assert oci_common_utils.is_dict_subset(s, t) is True
def test_is_dict_subset_when_source_or_target_are_not_dicts():
    assert oci_common_utils.is_dict_subset([], {}) is False
    assert oci_common_utils.is_dict_subset([], []) is False
    assert oci_common_utils.is_dict_subset("testsourcestr", {}) is False
    assert oci_common_utils.is_dict_subset(1, {}) is False
    assert oci_common_utils.is_dict_subset(True, {}) is False
    assert oci_common_utils.is_dict_subset({}, "testtargetstr") is False
    assert oci_common_utils.is_dict_subset({}, 1) is False
    assert oci_common_utils.is_dict_subset({}, True) is False
def test_is_dict_subset_returns_False_when_dicts_are_different():

    s = {"key1": "val1", "key2": "val2"}
    t = {"key1": "val1", "key2": "differentval2"}
    assert oci_common_utils.is_dict_subset(s, t) is False

    s = {"key1": "val1", "key2": "val2", "key3": {"subkey1": "subval1"}}
    t = {"key1": "val1", "key2": "val2", "key3": {"subkey1": "differentval1"}}
    assert oci_common_utils.is_dict_subset(s, t) is False

    s = {"key1": "val1", "key2": "val2", "key3": {"subkey1": True}}
    t = {"key1": "val1", "key2": "val2", "key3": {"subkey1": False}}
    assert oci_common_utils.is_dict_subset(s, t) is False

    s = {"key1": "val1", "key2": "val2", "key3": {"subkey1": 1}}
    t = {"key1": "val1", "key2": "val2", "key3": {"subkey1": "subval1"}}
    assert oci_common_utils.is_dict_subset(s, t) is False
 def get_matching_resource(self):
     create_model = self.get_create_model()
     attributes_to_consider = self.get_attributes_to_consider(create_model)
     for resource in self.list_resources():
         if not self._is_resource_active(resource):
             continue
         resource_dict = to_dict(resource)
         if oci_common_utils.is_dict_subset(
             source_dict=to_dict(create_model),
             target_dict=resource_dict,
             attrs=attributes_to_consider,
         ):
             return resource
     return None
def test_is_dict_subset_when_source_or_target_are_None():
    assert oci_common_utils.is_dict_subset(None, None) is False
    assert oci_common_utils.is_dict_subset({}, None) is False
    assert oci_common_utils.is_dict_subset(None, {}) is False
def test_is_dict_subset_when_dicts_have_dict_values():
    s = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    t = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {"key1": "val1", "key2": {"subkey1": {"subkey2": "subval2"}}}
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            },
            "subkey3": {
                "subkey4": "subval4"
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": {
                    "subkey3": "subval3"
                }
            }
        }
    }
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": {
                    "subkey3": "subval3",
                    "subkey4": "subval4"
                }
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            }
        },
        "key3": {}
    }
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            },
            "subkey3": {
                "subkey4": "subval4"
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is True
def test_is_dict_subset_when_source_and_target_are_empty():
    assert oci_common_utils.is_dict_subset({}, {}) is True
def test_is_dict_subset_when_dicts_have_list_values():
    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item2", "item3"]}
    assert oci_common_utils.is_dict_subset(s, t) is False

    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item2", "item3", "item1"]}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {"key1": "val1", "key2": ["item1", "item2", "item3"]}
    t = {"key1": "val1", "key2": ["item1", "item2", "item3", "item4"]}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags":
        None,
        "display_name":
        "db_system_rt_872",
        "freeform_tags":
        None,
        "route_rules": [{
            "cidr_block":
            "0.0.0.0/0",
            "destination":
            None,
            "destination_type":
            None,
            "network_entity_id":
            "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
        }],
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }

    t = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags": {},
        "display_name":
        "db_system_rt_872",
        "freeform_tags": {},
        "id":
        "ocid1.routetable.oc1.iad.xxxxxExamplexxx",
        "lifecycle_state":
        "AVAILABLE",
        "route_rules": [{
            "cidr_block":
            "0.0.0.0/0",
            "destination":
            "0.0.0.0/0",
            "destination_type":
            "CIDR_BLOCK",
            "network_entity_id":
            "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
        }],
        "time_created":
        "2019-07-18T18:41:09.752000+00:00",
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags":
        None,
        "display_name":
        "db_system_rt_872",
        "freeform_tags":
        None,
        "route_rules": [{
            "cidr_block":
            "0.0.0.0/0",
            "destination":
            None,
            "destination_type":
            None,
            "network_entity_id":
            "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
        }],
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }

    t = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags": {},
        "display_name":
        "db_system_rt_872",
        "freeform_tags": {},
        "id":
        "ocid1.routetable.oc1.iad.xxxxxExamplexxx",
        "lifecycle_state":
        "AVAILABLE",
        "route_rules": [
            {
                "cidr_block":
                "0.0.0.0/0",
                "destination":
                "0.0.0.0/0",
                "destination_type":
                "CIDR_BLOCK",
                "network_entity_id":
                "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
            },
            {
                "cidr_block":
                "1.2.3.4/16",
                "destination":
                "1.2.3.4/16",
                "destination_type":
                "CIDR_BLOCK",
                "network_entity_id":
                "ocid1.localpeeringgateway.oc1.iad.xxxxxExamplexxx",
            },
        ],
        "time_created":
        "2019-07-18T18:41:09.752000+00:00",
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags":
        None,
        "display_name":
        "db_system_rt_872",
        "freeform_tags":
        None,
        "route_rules": [
            {
                "cidr_block":
                "0.0.0.0/0",
                "destination":
                None,
                "destination_type":
                None,
                "network_entity_id":
                "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
            },
            {
                "cidr_block":
                "1.2.3.4/16",
                "destination":
                "1.2.3.4/16",
                "destination_type":
                "CIDR_BLOCK",
                "network_entity_id":
                "ocid1.localpeeringgateway.oc1.iad.xxxxxExamplexxx",
            },
        ],
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }

    t = {
        "compartment_id":
        "ocid1.compartment.oc1..xxxxxExamplexxx",
        "defined_tags": {},
        "display_name":
        "db_system_rt_872",
        "freeform_tags": {},
        "id":
        "ocid1.routetable.oc1.iad.xxxxxExamplexxx",
        "lifecycle_state":
        "AVAILABLE",
        "route_rules": [{
            "cidr_block":
            "0.0.0.0/0",
            "destination":
            "0.0.0.0/0",
            "destination_type":
            "CIDR_BLOCK",
            "network_entity_id":
            "ocid1.internetgateway.oc1.iad.xxxxxExamplexxx",
        }],
        "time_created":
        "2019-07-18T18:41:09.752000+00:00",
        "vcn_id":
        "ocid1.vcn.oc1.iad.xxxxxExamplexxx",
    }
    assert oci_common_utils.is_dict_subset(s, t) is False
def test_is_dict_subset_when_dicts_have_dict_values():
    s = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    t = {"key1": "val1", "key2": {"subkey1": "subval1", "subkey2": "subval2"}}
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {"key1": "val1", "key2": {"subkey1": {"subkey2": "subval2"}}}
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            },
            "subkey3": {
                "subkey4": "subval4"
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": {
                    "subkey3": "subval3"
                }
            }
        }
    }
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": {
                    "subkey3": "subval3",
                    "subkey4": "subval4"
                }
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is True

    s = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            }
        },
        "key3": {}
    }
    t = {
        "key1": "val1",
        "key2": {
            "subkey1": {
                "subkey2": "subval2"
            },
            "subkey3": {
                "subkey4": "subval4"
            }
        },
    }
    assert oci_common_utils.is_dict_subset(s, t) is False
    assert (oci_common_utils.is_dict_subset(
        s, t, ignore_attr_if_not_in_target=True) is True)