def test_CreateSession(self):
        """
        Create a session

        Assert:
            There is a high volume of granted credits
            A static rule is installed for redirection to the captive portal
            server
            Two dynamic rules are installed for traffic from UE to captive
            portal and vice versa
        """
        msg = CreateSessionRequest()
        msg.session_id = '1234'
        msg.imsi_plmn_id = '00101'
        resp = self.servicer.CreateSession(msg, None)

        # There should be a static rule installed for the redirection
        static_rules = self._rm_whitespace(str(resp.static_rules))
        expected = self._rm_whitespace(CSR_STATIC_RULES)
        self.assertEqual(
            static_rules, expected, 'There should be one static '
            'rule installed for redirection.')

        # Credit granted should be unlimited and un-metered
        credit_limit_type = resp.credits[0].limit_type
        expected = CreditLimitType.Value("INFINITE_UNMETERED")
        self.assertEqual(
            credit_limit_type, expected, 'There should be an '
            'infinite, unmetered credit grant')
Beispiel #2
0
 def _get_credits(self, sid: str) -> List[CreditUpdateResponse]:
     infinite_credit_keys = self.get_infinite_credit_charging_keys()
     postpay_keys = self._get_postpay_charging_keys()
     credit_updates = []
     for charging_key in infinite_credit_keys:
         credit_updates.append(
             CreditUpdateResponse(
                 success=True,
                 sid=sid,
                 charging_key=charging_key,
                 limit_type=CreditLimitType.Value("INFINITE_UNMETERED")))
     for charging_key in postpay_keys:
         credit_updates.append(
             CreditUpdateResponse(
                 success=True,
                 sid=sid,
                 charging_key=charging_key,
                 limit_type=CreditLimitType.Value("INFINITE_METERED")))
     return credit_updates
    def test_CreateSession(self):
        """
        Create a session

        Assert:
            There is a high volume of granted credits
            A static rule is installed for redirection to the captive portal
            server
            Two dynamic rules are installed for traffic from UE to captive
            portal and vice versa
        """
        msg = CreateSessionRequest(
            session_id='1234',
            common_context=CommonSessionContext(
                sid=SubscriberID(id='IMSI1234', ),
                apn='apn1',
            ),
            rat_specific_context=RatSpecificContext(
                lte_context=LTESessionContext(imsi_plmn_id='00101', ), ),
        )
        resp = self.servicer.CreateSession(msg, None)

        # There should be a static rule installed for the redirection
        static_rules = self._rm_whitespace(str(resp.static_rules))
        expected = self._rm_whitespace(CSR_STATIC_RULES)
        self.assertEqual(
            static_rules, expected, 'There should be one static '
            'rule installed for redirection.')

        # Credit granted should be unlimited and un-metered
        credit_limit_type = resp.credits[0].limit_type
        expected = CreditLimitType.Value("INFINITE_UNMETERED")
        self.assertEqual(
            credit_limit_type, expected, 'There should be an '
            'infinite, unmetered credit grant')

        msg_2 = CreateSessionRequest(
            session_id='2345',
            common_context=CommonSessionContext(
                sid=SubscriberID(id='IMSI2345', ),
                apn='apn2',
            ),
            rat_specific_context=RatSpecificContext(
                lte_context=LTESessionContext(imsi_plmn_id='00101', ), ),
        )
        resp = self.servicer.CreateSession(msg_2, None)

        # There should be a static rule installed
        static_rules = self._rm_whitespace(str(resp.static_rules))
        expected = self._rm_whitespace(CSR_STATIC_RULES_2)
        self.assertEqual(static_rules, expected, 'There should be one static '
                         'rule installed.')

        # Credit granted should be unlimited and un-metered
        credit_limit_type = resp.credits[0].limit_type
        expected = CreditLimitType.Value("INFINITE_UNMETERED")
        self.assertEqual(
            credit_limit_type, expected,
            'There should be an infinite, unmetered credit grant')

        msg_3 = CreateSessionRequest(
            session_id='3456',
            common_context=CommonSessionContext(
                sid=SubscriberID(id='IMSI3456', ),
                apn='apn1',
            ),
            rat_specific_context=RatSpecificContext(
                lte_context=LTESessionContext(imsi_plmn_id='00101', ), ),
        )
        resp = self.servicer.CreateSession(msg_3, None)

        # There should be a static rule installed
        static_rules = self._rm_whitespace(str(resp.static_rules))
        expected = self._rm_whitespace(CSR_STATIC_RULES_3)
        self.assertEqual(static_rules, expected, 'There should be one static '
                         'rule installed.')

        # Credit granted should be unlimited and un-metered
        credit_limit_type = resp.credits[0].limit_type
        expected = CreditLimitType.Value("INFINITE_UNMETERED")
        self.assertEqual(
            credit_limit_type, expected,
            'There should be an infinite, unmetered credit grant')