Пример #1
0
class SMPPBackendTestCase(DjangoTestCase):
    def setUp(self):
        self.backend = SMPPBackend()

    def test_init(self):
        for key in ['client', 'sender', 'sms_data_iter', 'sent_smses']:
            self.assert_(key in self.backend.__dict__.keys())

    def test_initialize_without_sms_request(self):
        self.assert_(self.backend._initialize(None) == False)

    def test_initialize_with_sms_request(self):
        sms_request = SMSRequest(**req_data)
        self.assert_(self.backend._initialize(sms_request) == True)

    def test_get_sms_list(self):
        sms_list = self.backend._get_sms_list(SMSRequest(**req_data))
        self.assert_(len(sms_list) == 3)
        for to, sms in zip(req_data['to'].split(';'), sms_list):
            self.assert_(sms.to[0] == check_cell_phone_number(to))
            self.assert_(sms.msg == truncate_sms(req_data['msg']))
            self.assertEqual(sms.signature,
                             req_data['signature'][:len(sms.signature)])

    def test_connect(self):
        self.assert_(self.backend.client == None)
        account_dict = settings.SMSGATEWAY_ACCOUNTS['smpp']
        self.backend._connect(account_dict)
        self.assert_(self.backend.client != None)
        self.assert_(self.backend.client.receiver_mode == True)
        self.assert_(self.backend.client.state == SMPP_CLIENT_STATE_BOUND_TRX)

    def test_connect_when_bind_fails(self):
        from mock import patch
        from smsgateway.smpplib.client import Client
        self.assert_(self.backend.client == None)
        patcher = patch.object(Client, 'bind_transceiver') 
        account_dict = settings.SMSGATEWAY_ACCOUNTS['smpp']
        with patcher as raise_exception:
            raise_exception.side_effect = Exception('Meeeck')
            self.backend._connect(account_dict)
        self.assert_(self.backend.client != None)
        self.assert_(self.backend.client.receiver_mode == False)
        self.assert_(self.backend.client.state == SMPP_CLIENT_STATE_CLOSED)
Пример #2
0
class SMPPBackendTestCase(DjangoTestCase):
    def setUp(self):
        self.backend = SMPPBackend()

    def test_init(self):
        for key in ['client', 'sender', 'sms_data_iter', 'sent_smses']:
            self.assert_(key in self.backend.__dict__.keys())

    def test_initialize_without_sms_request(self):
        self.assert_(self.backend._initialize(None) == False)

    def test_initialize_with_sms_request(self):
        sms_request = SMSRequest(**req_data)
        self.assert_(self.backend._initialize(sms_request) == True)

    def test_get_sms_list(self):
        sms_list = self.backend._get_sms_list(SMSRequest(**req_data))
        self.assert_(len(sms_list) == 3)
        for to, sms in zip(req_data['to'].split(';'), sms_list):
            self.assert_(sms.to[0] == check_cell_phone_number(to))
            self.assert_(sms.msg == truncate_sms(req_data['msg']))
            self.assertEqual(sms.signature,
                             req_data['signature'][:len(sms.signature)])

    def test_connect(self):
        self.assert_(self.backend.client == None)
        account_dict = settings.SMSGATEWAY_ACCOUNTS['smpp']
        self.backend._connect(account_dict)
        self.assert_(self.backend.client != None)
        self.assert_(self.backend.client.receiver_mode == True)
        self.assert_(self.backend.client.state == SMPP_CLIENT_STATE_BOUND_TRX)

    def test_connect_when_bind_fails(self):
        from mock import patch
        from smsgateway.smpplib.client import Client
        self.assert_(self.backend.client == None)
        patcher = patch.object(Client, 'bind_transceiver')
        account_dict = settings.SMSGATEWAY_ACCOUNTS['smpp']
        with patcher as raise_exception:
            raise_exception.side_effect = Exception('Meeeck')
            self.backend._connect(account_dict)
        self.assert_(self.backend.client != None)
        self.assert_(self.backend.client.receiver_mode == False)
        self.assert_(self.backend.client.state == SMPP_CLIENT_STATE_CLOSED)
Пример #3
0
class SMPPBackendTestCase(DjangoTestCase):
    def setUp(self):
        self.backend = SMPPBackend()

    def test_init(self):
        for key in ['client', 'sender', 'sms_data_iter', 'sent_smses']:
            assert key in list(self.backend.__dict__.keys())

    def test_initialize_without_sms_request(self):
        assert self.backend._initialize(None) is False

    def test_initialize_with_sms_request(self):
        sms_request = SMSRequest(**req_data)
        assert self.backend._initialize(sms_request) is True

    def test_get_sms_list(self):
        sms_list = self.backend._get_sms_list(SMSRequest(**req_data))
        assert len(sms_list) == 3
        for to, sms in zip(req_data['to'].split(';'), sms_list):
            assert sms.to[0] == check_cell_phone_number(to)
            assert sms.msg == truncate_sms(req_data['msg'])
            assert sms.signature == req_data['signature'][:len(sms.signature)]
Пример #4
0
class SMPPBackendTestCase(DjangoTestCase):
    def setUp(self):
        self.backend = SMPPBackend()

    def test_init(self):
        for key in ['client', 'sender', 'sms_data_iter', 'sent_smses']:
            assert key in list(self.backend.__dict__.keys())

    def test_initialize_without_sms_request(self):
        assert self.backend._initialize(None) is False

    def test_initialize_with_sms_request(self):
        sms_request = SMSRequest(**req_data)
        assert self.backend._initialize(sms_request) is True

    def test_get_sms_list(self):
        sms_list = self.backend._get_sms_list(SMSRequest(**req_data))
        assert len(sms_list) == 3
        for to, sms in zip(req_data['to'].split(';'), sms_list):
            assert sms.to[0] == check_cell_phone_number(to)
            assert sms.msg == truncate_sms(req_data['msg'])
            assert sms.signature == req_data['signature'][:len(sms.signature)]