コード例 #1
0
def runScenario(Request, method):
    try:
        proxy_router = RouterPBProxy()
        yield proxy_router.connect('127.0.0.1', 8988, 'radmin', 'rpwd')

        if method == "POST":
            smppUser = Request['username']
            smppPass = Request['password']
            smppThroughput = Request['tp']
            smppBindSessions = Request['sessions']

            if not smppUser:
                raise NameError('user')

            if len(smppPass) == 0 or len(smppPass) > 8:
                raise NameError('pass')

            if not smppThroughput.isdigit():
                raise NameError('tp')

            if not smppBindSessions.isdigit():
                raise NameError('session')

            # Provisiong router with users
            smpp_cred = SmppsCredential()
            yield smpp_cred.setQuota('max_bindings', int(smppBindSessions))
            mt_cred = MtMessagingCredential()
            yield mt_cred.setQuota('smpps_throughput', smppThroughput)
            #yield mt_cred.setQuota('submit_sm_count' , 500)

            g1 = Group('clients')
            u1 = User(uid=smppUser,
                      group=g1,
                      username=smppUser,
                      password=smppPass,
                      mt_credential=mt_cred,
                      smpps_credential=smpp_cred)
            yield proxy_router.group_add(g1)
            yield proxy_router.user_add(u1)
            print "Success"
        if method == 'DELETE':

            smppUser = Request['username']

            if not smppUser:
                raise NameError('user')

            yield proxy_router.user_remove(smppUser)
    except Exception, e:
        print "%s" % str(e)
コード例 #2
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_valuefilter(self):
        _cred = MtMessagingCredential()
        _cred.setValueFilter('content', '^HELLO$')

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred valuefilter content ^HELLO$'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setValueFilter('content', '^WORLD$')
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred valuefilter content ^WORLD$'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #3
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_quota(self):
        _cred = MtMessagingCredential()
        _cred.setQuota('balance', 40.3)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred quota balance 40.3'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setQuota('balance', 42)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota balance 42'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #4
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_authorization(self):
        _cred = MtMessagingCredential()
        _cred.setAuthorization('http_send', False)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred authorization http_send no'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('http_send', True)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred authorization http_send 1'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #5
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_defaultvalue(self):
        _cred = MtMessagingCredential()
        _cred.setDefaultValue('source_address', 'World')

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred defaultvalue src_addr World'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setDefaultValue('source_address', 'HELLO')
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred defaultvalue src_addr HELLO'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #6
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_increase_decrease_quota_int(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred quota sms_count 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        _cred = MtMessagingCredential()
        _cred.setQuota('submit_sm_count', 20)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count -90'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count +10'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #7
0
    def test_increase_decrease_quota_int(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred quota sms_count 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        _cred = MtMessagingCredential()
        _cred.setQuota('submit_sm_count', 20)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count -90'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count +10'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #8
0
    def test_increase_decrease_quota_invalid_type(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred quota sms_count 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        # Quota will remain the same since the following updates are using incorrect type
        _cred = MtMessagingCredential()
        _cred.setQuota('submit_sm_count', 100)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count -90.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count +10.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #9
0
ファイル: test_userm.py プロジェクト: AVert/jasmin
    def test_increase_unlimited_quota(self):
        "Related to #403"
        # Add user without initial quota
        extraCommands = [{'command': 'uid user_1'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        _cred = MtMessagingCredential()
        _cred.setQuota('submit_sm_count', 20)
        _cred.setQuota('balance', 11.2)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count +20'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota balance +11.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #10
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_increase_decrease_quota_invalid_type(self):
        # Add with initial quota
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred quota sms_count 100'}]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')

        # Quota will remain the same since the following updates are using incorrect type
        _cred = MtMessagingCredential()
        _cred.setQuota('submit_sm_count', 100)

        # Assert User increasing/decreasing quota
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count -90.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        extraCommands = [{'command': 'password anypassword'},
                         {'command': 'mt_messaging_cred quota sms_count +10.2'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #11
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_default(self):
        "Default user is created with a default MtMessagingCredential() instance"

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'}]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername',
                                                   MtMessagingCredential())

        # Assert User updating
        extraCommands = [{'command': 'password anypassword'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername',
                                                   MtMessagingCredential())
コード例 #12
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_defaultvalue(self):
        _cred = MtMessagingCredential()
        _cred.setDefaultValue('source_address', 'World')

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command':
            'mt_messaging_cred defaultvalue src_addr World'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)

        # Assert User updating
        _cred.setDefaultValue('source_address', 'HELLO')
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command':
            'mt_messaging_cred defaultvalue src_addr HELLO'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)
コード例 #13
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_valuefilter(self):
        _cred = MtMessagingCredential()
        _cred.setValueFilter('content', '^HELLO$')

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command':
            'mt_messaging_cred valuefilter content ^HELLO$'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)

        # Assert User updating
        _cred.setValueFilter('content', '^WORLD$')
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command':
            'mt_messaging_cred valuefilter content ^WORLD$'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)
コード例 #14
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_authorization(self):
        _cred = MtMessagingCredential()
        _cred.setAuthorization('http_send', False)

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command':
            'mt_messaging_cred authorization http_send no'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('http_send', True)
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command':
            'mt_messaging_cred authorization http_send 1'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)
コード例 #15
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_quota(self):
        _cred = MtMessagingCredential()
        _cred.setQuota('balance', 40.3)

        # Assert User adding
        extraCommands = [{
            'command': 'uid user_1'
        }, {
            'command': 'mt_messaging_cred quota balance 40.3'
        }]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)

        # Assert User updating
        _cred.setQuota('balance', 42)
        extraCommands = [{
            'command': 'password anypassword'
        }, {
            'command': 'mt_messaging_cred quota balance 42'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)
コード例 #16
0
def castToBuiltCorrectCredType(cred, section, key, value):
    'Will cast value to the correct type depending on the cred class, section and key'

    if cred == 'MtMessagingCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif key == 'balance' or key == 'early_decrement_balance_percent':
                value = float(value)
            elif key == 'submit_sm_count':
                value = int(value)
            elif key in ['http_throughput', 'smpps_throughput']:
                value = float(value)

        # Make a final validation: pass value to a temporarly MtMessagingCredential
        # object, an exception will be raised if the type is not correct
        _o = MtMessagingCredential()
        getattr(_o, 'set%s' % section)(key, value)
    elif cred == 'SmppsCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif key == 'max_bindings':
                value = int(value)

        # Make a final validation: pass value to a temporarly SmppsCredential
        # object, an exception will be raised if the type is not correct
        _o = SmppsCredential()
        getattr(_o, 'set%s' % section)(key, value)

    return value
コード例 #17
0
ファイル: test_userm.py プロジェクト: AndreiPlesa/jasmin
    def test_all(self):
        _cred = MtMessagingCredential()
        _cred.setAuthorization('http_send', False)
        _cred.setAuthorization('http_long_content', False)
        _cred.setAuthorization('set_dlr_level', False)
        _cred.setAuthorization('http_set_dlr_method', False)
        _cred.setAuthorization('set_source_address', False)
        _cred.setAuthorization('set_priority', False)
        _cred.setAuthorization('set_validity_period', False)
        _cred.setValueFilter('destination_address', '^HELLO$')
        _cred.setValueFilter('source_address', '^World$')
        _cred.setValueFilter('priority', '^1$')
        _cred.setValueFilter('validity_period', '^1$')
        _cred.setValueFilter('content', '[0-9].*')
        _cred.setDefaultValue('source_address', 'BRAND NAME')
        _cred.setQuota('balance', 40.3)
        _cred.setQuota('http_throughput', 2.2)
        _cred.setQuota('smpps_throughput', 0.5)

        # Assert User adding
        extraCommands = [{'command': 'uid user_1'},
                         {'command': 'mt_messaging_cred Authorization http_send no'},
                         {'command': 'mt_messaging_cred authorization http_long_content n'},
                         {'command': 'mt_messaging_cred authorization dlr_level 0'},
                         {'command': 'mt_messaging_cred authorization http_dlr_method NO'},
                         {'command': 'mt_messaging_cred authorization src_addr false'},
                         {'command': 'mt_messaging_cred authorization priority f'},
                         {'command': 'mt_messaging_cred authorization validity_period f'},
                         {'command': 'mt_messaging_cred Valuefilter dst_addr ^HELLO$'},
                         {'command': 'mt_messaging_cred valuefilter src_addr ^World$'},
                         {'command': 'mt_messaging_cred valuefilter priority ^1$'},
                         {'command': 'mt_messaging_cred valuefilter validity_period ^1$'},
                         {'command': 'mt_messaging_cred valuefilter content [0-9].*'},
                         {'command': 'mt_messaging_cred Defaultvalue src_addr BRAND NAME'},
                         {'command': 'mt_messaging_cred Quota balance 40.3'},
                         {'command': 'mt_messaging_cred quota http_throughput 2.2'},
                         {'command': 'mt_messaging_cred quota smpps_throughput 0.5'},
                        ]
        self.add_user(r'jcli : ', extraCommands, GID = 'AnyGroup', Username = '******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('http_send', True)
        _cred.setAuthorization('http_long_content', True)
        _cred.setAuthorization('set_dlr_level', True)
        _cred.setAuthorization('http_set_dlr_method', True)
        _cred.setAuthorization('set_source_address', True)
        _cred.setAuthorization('set_priority', True)
        _cred.setAuthorization('set_validity_period', True)
        _cred.setValueFilter('destination_address', '^WORLD$')
        _cred.setValueFilter('source_address', '^HELLO$')
        _cred.setValueFilter('priority', '^2$')
        _cred.setValueFilter('validity_period', '^2$')
        _cred.setValueFilter('content', '[2-6].*')
        _cred.setDefaultValue('source_address', 'SEXY NAME')
        _cred.setQuota('balance', 66)
        extraCommands = [{'command': 'mt_messaging_cred authorization http_send yes'},
                         {'command': 'mt_messaging_cred authorization http_long_content y'},
                         {'command': 'mt_messaging_cred authorization dlr_level 1'},
                         {'command': 'mt_messaging_cred authorization http_dlr_method YES'},
                         {'command': 'mt_messaging_cred authorization src_addr true'},
                         {'command': 'mt_messaging_cred authorization priority t'},
                         {'command': 'mt_messaging_cred authorization validity_period t'},
                         {'command': 'mt_messaging_cred valuefilter dst_addr ^WORLD$'},
                         {'command': 'mt_messaging_cred valuefilter src_addr ^HELLO$'},
                         {'command': 'mt_messaging_cred valuefilter priority ^2$'},
                         {'command': 'mt_messaging_cred valuefilter validity_period ^2$'},
                         {'command': 'mt_messaging_cred valuefilter content [2-6].*'},
                         {'command': 'mt_messaging_cred defaultvalue src_addr SEXY NAME'},
                         {'command': 'mt_messaging_cred quota balance 66'}]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup', 'AnyUsername', _cred)
コード例 #18
0
ファイル: test_userm.py プロジェクト: MeherBouhdid/jasmin
    def test_all(self):
        _cred = MtMessagingCredential()
        _cred.setAuthorization('http_send', False)
        _cred.setAuthorization('http_long_content', False)
        _cred.setAuthorization('set_dlr_level', False)
        _cred.setAuthorization('http_set_dlr_method', False)
        _cred.setAuthorization('set_source_address', False)
        _cred.setAuthorization('set_priority', False)
        _cred.setAuthorization('set_validity_period', False)
        _cred.setValueFilter('destination_address', '^HELLO$')
        _cred.setValueFilter('source_address', '^World$')
        _cred.setValueFilter('priority', '^1$')
        _cred.setValueFilter('validity_period', '^1$')
        _cred.setValueFilter('content', '[0-9].*')
        _cred.setDefaultValue('source_address', 'BRAND NAME')
        _cred.setQuota('balance', 40.3)
        _cred.setQuota('http_throughput', 2.2)
        _cred.setQuota('smpps_throughput', 0.5)

        # Assert User adding
        extraCommands = [
            {
                'command': 'uid user_1'
            },
            {
                'command': 'mt_messaging_cred authorization http_send no'
            },
            {
                'command':
                'mt_messaging_cred authorization http_long_content n'
            },
            {
                'command': 'mt_messaging_cred authorization dlr_level 0'
            },
            {
                'command': 'mt_messaging_cred authorization http_dlr_method NO'
            },
            {
                'command': 'mt_messaging_cred authorization src_addr false'
            },
            {
                'command': 'mt_messaging_cred authorization priority f'
            },
            {
                'command': 'mt_messaging_cred authorization validity_period f'
            },
            {
                'command': 'mt_messaging_cred valuefilter dst_addr ^HELLO$'
            },
            {
                'command': 'mt_messaging_cred valuefilter src_addr ^World$'
            },
            {
                'command': 'mt_messaging_cred valuefilter priority ^1$'
            },
            {
                'command': 'mt_messaging_cred valuefilter validity_period ^1$'
            },
            {
                'command': 'mt_messaging_cred valuefilter content [0-9].*'
            },
            {
                'command': 'mt_messaging_cred defaultvalue src_addr BRAND NAME'
            },
            {
                'command': 'mt_messaging_cred quota balance 40.3'
            },
            {
                'command': 'mt_messaging_cred quota http_throughput 2.2'
            },
            {
                'command': 'mt_messaging_cred quota smpps_throughput 0.5'
            },
        ]
        self.add_user(r'jcli : ',
                      extraCommands,
                      GID='AnyGroup',
                      Username='******')
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)

        # Assert User updating
        _cred.setAuthorization('http_send', True)
        _cred.setAuthorization('http_long_content', True)
        _cred.setAuthorization('set_dlr_level', True)
        _cred.setAuthorization('http_set_dlr_method', True)
        _cred.setAuthorization('set_source_address', True)
        _cred.setAuthorization('set_priority', True)
        _cred.setAuthorization('set_validity_period', True)
        _cred.setValueFilter('destination_address', '^WORLD$')
        _cred.setValueFilter('source_address', '^HELLO$')
        _cred.setValueFilter('priority', '^2$')
        _cred.setValueFilter('validity_period', '^2$')
        _cred.setValueFilter('content', '[2-6].*')
        _cred.setDefaultValue('source_address', 'SEXY NAME')
        _cred.setQuota('balance', 66)
        extraCommands = [{
            'command':
            'mt_messaging_cred authorization http_send yes'
        }, {
            'command':
            'mt_messaging_cred authorization http_long_content y'
        }, {
            'command':
            'mt_messaging_cred authorization dlr_level 1'
        }, {
            'command':
            'mt_messaging_cred authorization http_dlr_method YES'
        }, {
            'command':
            'mt_messaging_cred authorization src_addr true'
        }, {
            'command':
            'mt_messaging_cred authorization priority t'
        }, {
            'command':
            'mt_messaging_cred authorization validity_period t'
        }, {
            'command':
            'mt_messaging_cred valuefilter dst_addr ^WORLD$'
        }, {
            'command':
            'mt_messaging_cred valuefilter src_addr ^HELLO$'
        }, {
            'command':
            'mt_messaging_cred valuefilter priority ^2$'
        }, {
            'command':
            'mt_messaging_cred valuefilter validity_period ^2$'
        }, {
            'command':
            'mt_messaging_cred valuefilter content [2-6].*'
        }, {
            'command':
            'mt_messaging_cred defaultvalue src_addr SEXY NAME'
        }, {
            'command': 'mt_messaging_cred quota balance 66'
        }]
        self.update_user(r'jcli : ', 'user_1', extraCommands)
        self._test_user_with_MtMessagingCredential('user_1', 'AnyGroup',
                                                   'AnyUsername', _cred)
コード例 #19
0
def castToBuiltCorrectCredType(cred, section, key, value, update=False):
    'Will cast value to the correct type depending on the cred class, section and key'
    keep_original_value = None

    if cred == 'MtMessagingCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if (key in [
                        'balance', 'early_decrement_balance_percent',
                        'http_throughput', 'smpps_throughput'
                ]):
                    keep_original_value = float(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+f%s' % float(value)
                    value = abs(float(value))
                elif key == 'submit_sm_count':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif (key in [
                    'balance', 'early_decrement_balance_percent',
                    'http_throughput', 'smpps_throughput'
            ]):
                value = float(value)
            elif key == 'submit_sm_count':
                value = int(value)

        # Make a final validation: pass value to a temporarly MtMessagingCredential
        # object, an exception will be raised if the type is not correct
        _o = MtMessagingCredential()
        getattr(_o, 'set%s' % section)(key, value)
    elif cred == 'SmppsCredential':
        if section == 'Authorization':
            if value.lower() in TrueBoolCastMap:
                value = True
            elif value.lower() in FalseBoolCastMap:
                value = False
        elif section == 'Quota':
            if value.lower() == 'none':
                value = None
            elif update and value[:1] in ['+', '-']:
                if key == 'max_bindings':
                    keep_original_value = int(value)
                    if keep_original_value > 0:
                        # Since 'plus' sign will vanish, this is a way to keep track of it ...
                        # 'plus' and type of the value are encoded
                        keep_original_value = '+i%s' % int(value)
                    value = abs(int(value))
            elif key == 'max_bindings':
                value = int(value)

        # Make a final validation: pass value to a temporarly SmppsCredential
        # object, an exception will be raised if the type is not correct
        _o = SmppsCredential()
        getattr(_o, 'set%s' % section)(key, value)

    if keep_original_value is not None:
        return keep_original_value
    else:
        return value