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)]
def handle_incoming(self, request, reply_using=None): request_dict = request.POST if request.method == 'POST' else request.GET # Check whether we've gotten a SendDateTime if 'SendDateTime' not in request_dict: return HttpResponse('') # Check whether we've already received this message if SMS.objects.filter(gateway_ref=request_dict['MessageID']).exists(): return HttpResponse('OK') # Parse and process message year, month, day, hour, minute, second, ms = list(map(int, findall(r'(\d+)', request_dict['SendDateTime']))) sms_dict = { 'sent': datetime(year, month, day, hour, minute, second), 'content': request_dict['MsgeContent'], 'sender': check_cell_phone_number(request_dict['SenderGSMNR']), 'to': request_dict['ShortCode'], 'operator': int(request_dict['Operator']), 'gateway_ref': request_dict['MessageID'], 'backend': self.get_slug(), } sms = SMS(**sms_dict) response = self.process_incoming(request, sms) # If necessary, send response SMS if response is not None: signature = get_account(reply_using)['reply_signature'] success = send([sms.sender], response, signature, using=reply_using) # Sending failed, queue SMS if not success: send_queued(sms.sender, response, signature, reply_using) return HttpResponse(response) return HttpResponse('OK')
def test_multiple_sms_object_values(self): for to, sms in zip (req_data['to'].split(';'), self.smses): self.assert_(sms.to == check_cell_phone_number(to)) self.assert_(sms.content == truncate_sms(req_data['msg'])) self.assertEqual(sms.sender, req_data['signature'][:len(sms.sender)]) self.assert_(sms.backend == 'redistore')
def handle_incoming(self, request, reply_using=None): request_dict = request.POST if request.method == 'POST' else request.GET # Check whether we've got an id if 'id' not in request_dict: return HttpResponse('') # Check whether we've already received this message if SMS.objects.filter(gateway_ref=request_dict['id']).exists(): return HttpResponse('ACK/Jasmin') # Parse and process message sms_dict = { 'sent': datetime.now(), 'content': request_dict['content'], 'sender': check_cell_phone_number(request_dict['from']), 'to': request_dict['to'], 'gateway_ref': request_dict['id'], 'backend': self.get_slug(), } sms = SMS(**sms_dict) response = self.process_incoming(request, sms) # If necessary, send response SMS if response is not None: signature = get_account(reply_using)['reply_signature'] success = send([sms.sender], response, signature, using=reply_using) # Sending failed, queue SMS if not success: send_queued(sms.sender, response, signature, reply_using) return HttpResponse('ACK/Jasmin')
def test_multiple_sms_object_values(self): for to, sms in zip(req_data['to'].split(';'), self.smses): self.assert_(sms.to == check_cell_phone_number(to)) self.assert_(sms.content == truncate_sms(req_data['msg'])) self.assertEqual(sms.sender, req_data['signature'][:len(sms.sender)]) self.assert_(sms.backend == 'redistore')
def test_send_multiple_separated_sms(self): self.assert_(SMS.objects.count() == 0) send(req_data['to'], req_data['msg'], req_data['signature'], using='smpp') self.assert_(SMS.objects.count() == 3) smses = SMS.objects.all() for to, sms in zip (req_data['to'].split(';'), smses): self.assert_(sms.to == check_cell_phone_number(to)) self.assert_(sms.content == truncate_sms(req_data['msg'])) self.assertEqual(sms.sender, req_data['signature'][:len(sms.sender)]) self.assert_(sms.backend == 'smpp')
def __init__(self, to, msg, signature, reliable=False, reference=None): """ The 'to' parameter is a list of mobile numbers including country prefix. The 'msg' parameter is a unicode object of 160 characters. Please keep in mind that the actual supported character set depends on the SMS gateway provider and phone model. The validity of the 'signature' depends on the SMS gateway provider you are using. >>> sms_request = SMSRequest(to='+32472123456;+3298723456', u'Hello, world!', signature='9898') """ self.to = [check_cell_phone_number(n) for n in (to.split(';') if isinstance(to, basestring) else to)] self.msg = truncate_sms(msg) self.signature = signature[:16] if signature[1:].isdigit() else signature[:11] self.reliable = reliable self.reference = reference
def test_send_multiple_separated_sms(self): self.assert_(SMS.objects.count() == 0) send(req_data['to'], req_data['msg'], req_data['signature'], using='smpp') self.assert_(SMS.objects.count() == 3) smses = SMS.objects.all() for to, sms in zip(req_data['to'].split(';'), smses): self.assert_(sms.to == check_cell_phone_number(to)) self.assert_(sms.content == truncate_sms(req_data['msg'])) self.assertEqual(sms.sender, req_data['signature'][:len(sms.sender)]) self.assert_(sms.backend == 'smpp')
def __init__(self, to, msg, signature, reliable=False, reference=None): """ The 'to' parameter is a list of mobile numbers including country prefix. The 'msg' parameter is a unicode object of 160 characters. Please keep in mind that the actual supported character set depends on the SMS gateway provider and phone model. The validity of the 'signature' depends on the SMS gateway provider you are using. >>> sms_request = SMSRequest(to='+32472123456;+3298723456', u'Hello, world!', signature='9898') """ self.to = [ check_cell_phone_number(n) for n in (to.split(';') if isinstance(to, basestring) else to) ] self.msg = truncate_sms(msg) self.signature = signature[:16] if signature[1:].isdigit( ) else signature[:11] self.reliable = reliable self.reference = reference
def handle_incoming(self, request, reply_using=None): request_dict = request.POST if request.method == 'POST' else request.GET # Check whether we've gotten a SendDateTime if not 'SendDateTime' in request_dict: return HttpResponse('') # Check whether we've already received this message if SMS.objects.filter(gateway_ref=request_dict['MessageID']).exists(): return HttpResponse('OK') # Parse and process message year, month, day, hour, minute, second, ms = map( int, re.findall(r'(\d+)', request_dict['SendDateTime'])) sms_dict = { 'sent': datetime.datetime(year, month, day, hour, minute, second), 'content': request_dict['MsgeContent'], 'sender': check_cell_phone_number(request_dict['SenderGSMNR']), 'to': request_dict['ShortCode'], 'operator': int(request_dict['Operator']), 'gateway_ref': request_dict['MessageID'], 'backend': self.get_slug(), } sms = SMS(**sms_dict) response = self.process_incoming(request, sms) # If necessary, send response SMS if response is not None: signature = smsgateway.get_account(reply_using)['reply_signature'] success = smsgateway.send([sms.sender], response, signature, using=reply_using) # Sending failed, queue SMS if not success: smsgateway.send_queued(sms.sender, response, signature, reply_using) return HttpResponse(response) return HttpResponse('OK')
def test_international_format(self): return check_cell_phone_number('+32478123456') == '32478123456'
def test_national_format_without_leading_zero(self): return check_cell_phone_number('478123456') == '32478123456'
def test_international_format_without_plus(self): return check_cell_phone_number('32478123456') == '32478123456'