tests: add a test for SMS workflow action
This commit is contained in:
parent
2fc4aadda0
commit
88e9660ea2
|
@ -9,7 +9,8 @@ from wcs.qommon.http_request import HTTPRequest
|
|||
from wcs.formdef import FormDef
|
||||
from wcs import sessions
|
||||
from wcs.roles import Role
|
||||
from wcs.workflows import Workflow, WorkflowStatusItem, SendmailWorkflowStatusItem
|
||||
from wcs.workflows import (Workflow, WorkflowStatusItem,
|
||||
SendmailWorkflowStatusItem, SendSMSWorkflowStatusItem)
|
||||
from wcs.wf.anonymise import AnonymiseWorkflowStatusItem
|
||||
from wcs.wf.dispatch import DispatchWorkflowStatusItem
|
||||
from wcs.wf.jump import JumpWorkflowStatusItem, _apply_timeouts
|
||||
|
@ -19,7 +20,7 @@ from wcs.wf.roles import AddRoleWorkflowStatusItem, RemoveRoleWorkflowStatusItem
|
|||
from wcs.wf.wscall import WebserviceCallStatusItem
|
||||
|
||||
from utilities import (create_temporary_pub, MockSubstitutionVariables, emails,
|
||||
http_requests, clean_temporary_pub)
|
||||
http_requests, clean_temporary_pub, sms_mocking)
|
||||
|
||||
def setup_module(module):
|
||||
cleanup()
|
||||
|
@ -461,3 +462,31 @@ def test_timeout_then_remove(two_pubs):
|
|||
_apply_timeouts(pub)
|
||||
|
||||
assert not str(formdata_id) in [str(x) for x in formdef.data_class().keys()]
|
||||
|
||||
def test_sms():
|
||||
formdef = FormDef()
|
||||
formdef.name = 'baz'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
formdata.store()
|
||||
|
||||
item = SendSMSWorkflowStatusItem()
|
||||
item.to = ['000']
|
||||
item.body = 'XXX'
|
||||
item.perform(formdata) # nothing
|
||||
assert sms_mocking.sms[-1]['destinations'] == ['000']
|
||||
assert sms_mocking.sms[-1]['text'] == 'XXX'
|
||||
sms_mocking.empty()
|
||||
|
||||
# check None as recipient is not passed to the SMS backend
|
||||
item.to = [None]
|
||||
item.perform(formdata) # nothing
|
||||
assert len(sms_mocking.sms) == 0
|
||||
|
||||
item.to = ['000', None]
|
||||
item.perform(formdata) # nothing
|
||||
assert sms_mocking.sms[-1]['destinations'] == ['000']
|
||||
assert sms_mocking.sms[-1]['text'] == 'XXX'
|
||||
|
|
|
@ -19,6 +19,8 @@ from wcs import publisher
|
|||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.users import User
|
||||
from wcs.tracking_code import TrackingCode
|
||||
import wcs.qommon.sms
|
||||
import qommon.sms
|
||||
|
||||
class QWIP:
|
||||
# copy of quixote original QWIP code, adapted to use our own HTTPRequest
|
||||
|
@ -224,3 +226,25 @@ class HttpRequestsMocking(object):
|
|||
self.requests = []
|
||||
|
||||
http_requests = HttpRequestsMocking()
|
||||
|
||||
|
||||
class SMSMocking(wcs.qommon.sms.MobytSMS):
|
||||
def __init__(self):
|
||||
wcs.qommon.sms.SMS.get_sms_class = classmethod(lambda x, y: self)
|
||||
qommon.sms.SMS.get_sms_class = classmethod(lambda x, y: self)
|
||||
self.sms = []
|
||||
|
||||
def send(self, sender, destinations, text, quality=None):
|
||||
self.sms.append({'sender': sender, 'destinations': destinations,
|
||||
'text': text})
|
||||
|
||||
def empty(self):
|
||||
self.sms = []
|
||||
|
||||
def get_sms_left(self, type='standard'):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_money_left(self):
|
||||
raise NotImplementedError
|
||||
|
||||
sms_mocking = SMSMocking()
|
||||
|
|
Loading…
Reference in New Issue