示例#1
0
class RuleMappersTest(unittest.TestCase):
    def setUp(self):
        self._session_rule_version_mapper = SessionRuleToVersionMapper()
        self._session_rule_version_mapper._version_by_imsi_and_rule = {}

    def test_session_rule_version_mapper(self):
        rule_ids = ['rule1', 'rule2']
        imsi = 'IMSI12345'
        self._session_rule_version_mapper.update_version(imsi, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(imsi, rule_ids[0]),
            1)

        self._session_rule_version_mapper.update_version(imsi, rule_ids[1])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(imsi, rule_ids[1]),
            1)

        self._session_rule_version_mapper.update_version(imsi, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(imsi, rule_ids[0]),
            2)

        # Test updating version for all rules of a subscriber
        self._session_rule_version_mapper.update_version(imsi, None)

        self.assertEqual(
            self._session_rule_version_mapper.get_version(imsi, rule_ids[0]),
            3)
        self.assertEqual(
            self._session_rule_version_mapper.get_version(imsi, rule_ids[1]),
            2)
示例#2
0
class RuleMappersTest(unittest.TestCase):
    def setUp(self):
        self._session_rule_version_mapper = SessionRuleToVersionMapper()
        self._session_rule_version_mapper._version_by_imsi_and_rule = {}

    def test_session_rule_version_mapper(self):
        rule_ids = ['rule1', 'rule2']
        imsi = 'IMSI12345'
        ip_addr = '1.2.3.4'
        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 2)

        # Test updating version for all rules of a subscriber
        self._session_rule_version_mapper.update_version(imsi, None)

        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 3)
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1]), 2)

    def test_session_rule_version_mapper_cwf(self):
        rule_ids = ['rule1', 'rule2']
        imsi = 'IMSI12345'
        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[1])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[1]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 2)

        # Test updating version for all rules of a subscriber
        self._session_rule_version_mapper.update_version(imsi, None)

        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 3)
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[1]), 2)
示例#3
0
class RuleMappersTest(unittest.TestCase):
    def setUp(self):
        # mock the get_default_client function used to return a fakeredis object
        func_mock = MagicMock(return_value=fakeredis.FakeStrictRedis())
        with mock.patch('magma.pipelined.rule_mappers.get_default_client',
                        func_mock):
            self._session_rule_version_mapper = SessionRuleToVersionMapper()
        self._session_rule_version_mapper._version_by_imsi_and_rule = {}

    def test_session_rule_version_mapper(self):
        rule_ids = ['rule1', 'rule2']
        imsi = 'IMSI12345'
        ip_addr = '1.2.3.4'
        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 2)

        # Test updating version for all rules of a subscriber
        self._session_rule_version_mapper.update_version(imsi, None)

        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[0]), 3)
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, convert_ipv4_str_to_ip_proto(ip_addr), rule_ids[1]), 2)

    def test_session_rule_version_mapper_cwf(self):
        rule_ids = ['rule1', 'rule2']
        imsi = 'IMSI12345'
        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[1])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[1]), 1)

        self._session_rule_version_mapper.update_version(
            imsi, None, rule_ids[0])
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 2)

        # Test updating version for all rules of a subscriber
        self._session_rule_version_mapper.update_version(imsi, None)

        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[0]), 3)
        self.assertEqual(
            self._session_rule_version_mapper.get_version(
                imsi, None, rule_ids[1]), 2)