def test_02_http(self): ''' Test the HTTP sms provider ''' phone = "1234567890" message = "123456" ret = False clickatell_config = { 'URL' : 'http://api.clickatell.com/http/sendmsg', 'PARAMETER' : { 'user':'******', 'password':'******', 'api_id':'askme', }, 'SMS_TEXT_KEY':'text', 'SMS_PHONENUMBER_KEY':'to', 'HTTP_Method':'GET', "RETURN_SUCCESS":"ID" } config = {'URL':'http://localhost/cgi-perl/prepaid/private/smsversand.cgi', 'PARAMETER': { 'von':'OWN_NUMBER', 'passwort':'PASSWORD', 'absender':'TYPE', 'konto':'1' }, 'SMS_TEXT_KEY':'text', 'SMS_PHONENUMBER_KEY':'ziel', 'HTTP_Method':'GET', "RETURN_SUCCESS":"ID" } sms = getSMSProviderClass("HttpSMSProvider", "HttpSMSProvider")() # # dependend from the test envionment we receive different # error messages like: # # "Failed to send SMS. \ # We received a none success reply from the SMS Gateway. . . . # or # "Failed to send SMS. \ # HTTPConnectionPool(host='localhost', port=80) . . . # # so the test for the error message is adjusted to # msg = ("Failed to send SMS") with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(clickatell_config) ret = sms.submitMessage(phone, message) self.assertFalse(ret) with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(config) ret = sms.submitMessage(phone, message) self.assertFalse(ret)
def test_02_http(self): ''' Test the HTTP sms provider ''' phone = "1234567890" message = "123456" ret = False clickatell_config = {'URL': 'http://api.clickatell.com/http/sendmsg', 'PARAMETER': { 'user': '******', 'password': '******', 'api_id': 'askme', }, 'SMS_TEXT_KEY': 'text', 'SMS_PHONENUMBER_KEY': 'to', 'HTTP_Method': 'GET', "RETURN_SUCCESS": "ID" } config = {'URL': 'http://localhost/cgi-perl/prepaid/private/smsversand.cgi', 'PARAMETER': { 'von': 'OWN_NUMBER', 'passwort': 'PASSWORD', 'absender': 'TYPE', 'konto': '1' }, 'SMS_TEXT_KEY': 'text', 'SMS_PHONENUMBER_KEY': 'ziel', 'HTTP_Method': 'GET', "RETURN_SUCCESS": "ID" } sms = getSMSProviderClass("HttpSMSProvider", "HttpSMSProvider")() # # dependend from the test envionment we receive different # error messages like: # # "Failed to send SMS. \ # We received a none success reply from the SMS Gateway. . . . # or # "Failed to send SMS. \ # HTTPConnectionPool(host='localhost', port=80) . . . # # so the test for the error message is adjusted to # msg = ("Failed to send SMS") with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(clickatell_config) ret = sms.submitMessage(phone, message) self.assertFalse(ret) with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(config) ret = sms.submitMessage(phone, message) self.assertFalse(ret)
def main(phone, message): print "SMSProvider - class load test " # echo "text" | gnokii --config <filename> <ziel> config = {'CONFIGFILE': '/home/user/.gnokiirc', } sms = getSMSProviderClass("DeviceSMSProvider", "DeviceSMSProvider")() sms.loadConfig(config) ret = sms.submitMessage(phone, message) print sms
def test_02_http(self): ''' Test the HTTP sms provider ''' phone = "1234567890" message = "123456" ret = False clickatell_config = { 'URL': 'http://api.clickatell.com/http/sendmsg', 'PARAMETER': { 'user': '******', 'password': '******', 'api_id': 'askme', }, 'SMS_TEXT_KEY': 'text', 'SMS_PHONENUMBER_KEY': 'to', 'HTTP_Method': 'GET', "RETURN_SUCCESS": "ID" } config = { 'URL': 'http://localhost/cgi-perl/prepaid/private/smsversand.cgi', 'PARAMETER': { 'von': 'OWN_NUMBER', 'passwort': 'PASSWORD', 'absender': 'TYPE', 'konto': '1' }, 'SMS_TEXT_KEY': 'text', 'SMS_PHONENUMBER_KEY': 'ziel', 'HTTP_Method': 'GET', "RETURN_SUCCESS": "ID" } sms = getSMSProviderClass("HttpSMSProvider", "HttpSMSProvider")() msg = ("Failed to send SMS. We received a none success reply from" " the SMS Gateway.") with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(clickatell_config) ret = sms.submitMessage(phone, message) self.assertFalse(ret) msg = "Connection refused" with self.assertRaisesRegexp(Exception, msg): sms.loadConfig(config) ret = sms.submitMessage(phone, message) self.assertFalse(ret)
def test_01_smtp(self): """ This test will fail, since the mailserver does not exist """ phone = "1234567890" message = "123456" smtp_config = { "mailserver": "xxx.yyy.zz", "mailsender": "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", "mailto": "*****@*****.**", "subject": "<phone>", "body": "This is the otp value: <otp>", "raise_exception": True, } sms = getSMSProviderClass("SmtpSMSProvider", "SmtpSMSProvider")() sms.loadConfig(smtp_config) with pytest.raises(ProviderNotAvailable): sms.submitMessage(phone, message) smtp_config = { "mailserver": "localhost:1025", "mailsender": "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", "mailto": "*****@*****.**", "subject": "<phone>", "body": "This is the otp value: <otp>", "raise_exception": False, } sms.loadConfig(smtp_config) ret = sms.submitMessage(phone, message) assert ret is False, ret smtp_config["raise_exception"] = True sms.loadConfig(smtp_config) with pytest.raises( Exception, match="Connection refused|Cannot assign requested address", ): sms.submitMessage(phone, message)
def test_01_smtp(self): ''' This test will fail, since the mailserver does not exist ''' phone = "1234567890" message = "123456" smtp_config = { 'mailserver': 'xxx.yyy.zz', 'mailsender': "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", 'mailto': '*****@*****.**', 'subject': '<phone>', 'body': 'This is the otp value: <otp>', 'raise_exception': True } sms = getSMSProviderClass("SmtpSMSProvider", "SmtpSMSProvider")() sms.loadConfig(smtp_config) with self.assertRaisesRegexp(Exception, "Name or service not known"): sms.submitMessage(phone, message) smtp_config = { 'mailserver': 'localhost:1025', 'mailsender': "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", 'mailto': '*****@*****.**', 'subject': '<phone>', 'body': 'This is the otp value: <otp>', 'raise_exception': False } sms.loadConfig(smtp_config) ret = sms.submitMessage(phone, message) self.assertTrue(ret is False, ret) smtp_config['raise_exception'] = True sms.loadConfig(smtp_config) with self.assertRaisesRegexp( Exception, "Connection refused|Cannot assign requested address"): sms.submitMessage(phone, message)
def test_01_smtp(self): ''' This test will fail, since the mailserver does not exist ''' phone = "1234567890" message = "123456" smtp_config = {'mailserver': 'xxx.yyy.zz', 'mailsender': "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", 'mailto': '*****@*****.**', 'subject': '<phone>', 'body': 'This is the otp value: <otp>', 'raise_exception': True} sms = getSMSProviderClass("SmtpSMSProvider", "SmtpSMSProvider")() sms.loadConfig(smtp_config) with self.assertRaises(ProviderNotAvailable): sms.submitMessage(phone, message) smtp_config = {'mailserver': 'localhost:1025', 'mailsender': "*****@*****.**", # 'mailuser' : "useraccount", # 'mailpassword' : "somesecret", 'mailto': '*****@*****.**', 'subject': '<phone>', 'body': 'This is the otp value: <otp>', 'raise_exception': False} sms.loadConfig(smtp_config) ret = sms.submitMessage(phone, message) self.assertTrue(ret is False, ret) smtp_config['raise_exception'] = True sms.loadConfig(smtp_config) with self.assertRaisesRegexp(Exception, "Connection refused|Cannot assign requested address"): sms.submitMessage(phone, message)
def test_02_http(self): """ Test the HTTP sms provider """ phone = "1234567890" message = "123456" ret = False clickatell_config = { "URL": "http://api.clickatell.com/http/sendmsg", "PARAMETER": { "user": "******", "password": "******", "api_id": "askme", }, "SMS_TEXT_KEY": "text", "SMS_PHONENUMBER_KEY": "to", "HTTP_Method": "GET", "RETURN_SUCCESS": "ID", } config = { "URL": "http://localhost/cgi-perl/prepaid/private/smsversand.cgi", "PARAMETER": { "von": "OWN_NUMBER", "passwort": "PASSWORD", "absender": "TYPE", "konto": "1", }, "SMS_TEXT_KEY": "text", "SMS_PHONENUMBER_KEY": "ziel", "HTTP_Method": "GET", "RETURN_SUCCESS": "ID", } sms = getSMSProviderClass("HttpSMSProvider", "HttpSMSProvider")() # # dependend from the test envionment we receive different # error messages like: # # "Failed to send SMS. \ # We received a none success reply from the SMS Gateway. . . . # or # "Failed to send SMS. \ # HTTPConnectionPool(host='localhost', port=80) . . . # # so the test for the error message is adjusted to # msg = "Failed to send SMS" with pytest.raises(Exception, match=msg): sms.loadConfig(clickatell_config) ret = sms.submitMessage(phone, message) assert not ret with pytest.raises(Exception, match=msg): sms.loadConfig(config) ret = sms.submitMessage(phone, message) assert not ret