# Path: networking_bgpvpn/neutron/services/common/utils.py
# def filter_resource(resource, filters=None):
#     if not filters:
#         filters = {}
#     for key, value in filters.items():
#         if key in resource.keys():
#             if not isinstance(value, list):
#                 value = [value]
#             if isinstance(resource[key], list):
#                 resource_value = resource[key]
#             else:
#                 resource_value = [resource[key]]
#             if not set(value).issubset(set(resource_value)):
#                 return False
#     return True


from neutron.tests import base
from networking_bgpvpn.neutron.services.common.utils import filter_resource
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




class TestFilterResource(base.BaseTestCase):
    _fake_resource_string = {
        'fake_attribute': 'fake_value1',
    }
    _fake_resource_list = {
        'fake_attribute': ['fake_value1', 'fake_value2', 'fake_value3'],
    }

    def test_filter_resource_succeeds_with_one_value(self):
        filters = {
            'fake_attribute': 'fake_value1',
        }
        self.assertTrue(filter_resource(self._fake_resource_string, filters))
        self.assertTrue(filter_resource(self._fake_resource_list, filters))

    def test_filter_resource_fails_with_one_value(self):
        filters = {
            'fake_attribute': 'wrong_fake_value1',
        }
        self.assertFalse(filter_resource(self._fake_resource_string, filters))

# Path: networking_bgpvpn/neutron/services/common/utils.py
# def filter_resource(resource, filters=None):
#     if not filters:
#         filters = {}
#     for key, value in filters.items():
#         if key in resource.keys():
#             if not isinstance(value, list):
#                 value = [value]
#             if isinstance(resource[key], list):
#                 resource_value = resource[key]
#             else:
#                 resource_value = [resource[key]]
#             if not set(value).issubset(set(resource_value)):
#                 return False
#     return True


# Path: networking_bgpvpn/tests/unit/services/common/test_utils.py
from neutron.tests import base
from networking_bgpvpn.neutron.services.common.utils import filter_resource

#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




class TestFilterResource(base.BaseTestCase):
    _fake_resource_string = {
        'fake_attribute': 'fake_value1',
    }
    _fake_resource_list = {
        'fake_attribute': ['fake_value1', 'fake_value2', 'fake_value3'],
    }

    def test_filter_resource_succeeds_with_one_value(self):
        filters = {
            'fake_attribute': 'fake_value1',
        }
        self.assertTrue(filter_resource(self._fake_resource_string, filters))
        self.assertTrue(filter_resource(self._fake_resource_list, filters))

    def test_filter_resource_fails_with_one_value(self):
        filters = {
            'fake_attribute': 'wrong_fake_value1',
        }
        self.assertFalse(filter_resource(self._fake_resource_string, filters))

        self.assertFalse(filter_resource(self._fake_resource_list, filters))