def test_daily_account_summary(self): msg_helper = GoMessageHelper(vumi_helper=self.vumi_helper) conv = self.user_helper.create_conversation( u'bulk_message', name=u'Test Conversation', started=True) self.user_helper.contact_store.new_contact( name=u'Contact', surname=u'One', msisdn=u"+27761234567") self.user_helper.contact_store.new_contact( name=u'Contact', surname=u'Two', msisdn=u"+27761234567") msgs = msg_helper.add_inbound_to_conv(conv, 5) msg_helper.add_replies_to_conv(conv, msgs) # create a second conversation to test sorting self.user_helper.create_conversation(u'bulk_message') django_user = self.user_helper.get_django_user() # schedule the task send_user_account_summary(django_user) [email] = mail.outbox self.assertEqual(email.subject, 'Vumi Go Account Summary') self.assertEqual(email.from_email, settings.DEFAULT_FROM_EMAIL) self.assertEqual(email.recipients(), [django_user.email]) self.assertTrue('number of contacts: 2' in email.body) self.assertTrue('number of unique contacts by contact number: 1' in email.body) self.assertTrue('number of messages sent: 5' in email.body) self.assertTrue('number of messages received: 5' in email.body) self.assertTrue('Group Message' in email.body) self.assertTrue('Test Conversation' in email.body) self.assertTrue('Sent: 5 to 5 uniques.' in email.body) self.assertTrue('Received: 5 from 5 uniques.' in email.body) self.assertTrue('"Group Message" Sent: 5' in email.body) self.assertTrue('"Group Message" Received: 5' in email.body)
def setUp(self): super(TestMessageStoreResource, self).setUp() self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.msg_helper = self.add_helper(GoMessageHelper()) self.user_helper = yield self.vumi_helper.make_user(u"user") self.app_worker.user_api = self.user_helper.user_api self.message_store = self.vumi_helper.get_vumi_api().mdb self.conversation = yield self.user_helper.create_conversation( u'jsbox', started=True) # store inbound yield self.message_store.add_inbound_message( self.msg_helper.make_inbound('hello'), batch_id=self.conversation.batch.key) # store outbound outbound_msg = self.msg_helper.make_outbound('hello') yield self.message_store.add_outbound_message( outbound_msg, batch_id=self.conversation.batch.key) # ack outbound event = self.msg_helper.make_ack(outbound_msg) yield self.message_store.add_event(event) # monkey patch for when no conversation_key is provided self.app_worker.conversation_for_api = lambda *a: self.conversation yield self.create_resource({})
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.msg_helper = self.add_helper( GoMessageHelper(vumi_helper=self.vumi_helper)) self.user_helper = yield self.vumi_helper.make_user(u'user') self.conv = yield self.user_helper.create_conversation( conversation_type=u'some_conversation')
def setUp(self): super(TestGoOutboundResource, self).setUp() yield self.create_resource({}) self.vumi_helper = yield self.add_helper(VumiApiHelper(), setup_vumi_api=True) self.app_helper = self.add_helper( ApplicationHelper(u"dummy", self.vumi_helper)) self.msg_helper = self.add_helper(GoMessageHelper())
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.msg_helper = self.add_helper(GoMessageHelper()) self.billing_api = BillingApiMock() self.ri_helper = self.vumi_helper.get_worker_helper( "billing_dispatcher_ri") self.ro_helper = self.vumi_helper.get_worker_helper( "billing_dispatcher_ro")
def __init__(self, middleware_class): self._vumi_helper = VumiApiHelper() self._msg_helper = GoMessageHelper() self.middleware_class = middleware_class self._middlewares = [] generate_proxies(self, self._vumi_helper) generate_proxies(self, self._msg_helper)
def test_stats(self): msg_helper = GoMessageHelper(vumi_helper=self.vumi_helper) conv = self.user_helper.create_conversation( u'bulk_message', name=u'active', started=True) msgs = msg_helper.add_inbound_to_conv(conv, 5, time_multiplier=0) msg_helper.add_replies_to_conv(conv, msgs) self.command.handle(self.user_email, 'stats', conv.key) output = self.command.stdout.getvalue().strip().split('\n') self.assertEqual(output, [ u'Conversation: active', u'Total Received in batch %s: 5' % (conv.batch.key,), u'Total Sent in batch %s: 5' % (conv.batch.key,), u'Total Uniques: 5', u'Received per date:', u'%s: 5' % (datetime.now().date(),), u'Sent per date:', u'%s: 5' % (datetime.now().date(),), ])
def setup_fix_batches(self, tags=(), num_batches=1): mdb = self.user_api.api.mdb msg_helper = GoMessageHelper() # We can't use .store_*(), so no mdb. batches = [mdb.batch_start(tags=tags) for i in range(num_batches)] conv = self.mkoldconv( create_batch=False, conversation_type=u'dummy_type', name=u'Dummy Conv 1', description=u'Dummy Description', config={}) for i, batch_id in enumerate(batches): conv.batches.add_key(batch_id) msg1 = msg_helper.make_inbound("in", message_id=u"msg-%d" % i) mdb.add_inbound_message(msg1, batch_id=batch_id) msg2 = msg_helper.make_outbound("out", message_id=u"msg-%d" % i) mdb.add_outbound_message(msg2, batch_id=batch_id) conv.save() return conv
def __init__(self, worker_class, **msg_helper_args): self._worker_class = worker_class msg_helper_kw = {} if msg_helper_args is not None: msg_helper_kw.update(msg_helper_args) self.vumi_helper = VumiApiHelper() self._router_helper = RouterHelper( self._router_type(), self.vumi_helper) self.msg_helper = GoMessageHelper(**msg_helper_kw) # Proxy methods from our helpers. generate_proxies(self, self._router_helper) generate_proxies(self, self.msg_helper) self.ri = RouterConnectorHelper( 'ri_conn', self.vumi_helper, self.msg_helper) self.ro = RouterConnectorHelper( 'ro_conn', self.vumi_helper, self.msg_helper)
def test_stats(self): msg_helper = GoMessageHelper(vumi_helper=self.vumi_helper) conv = self.user_helper.create_conversation(u'bulk_message', name=u'active', started=True) msgs = msg_helper.add_inbound_to_conv(conv, 5, time_multiplier=0) msg_helper.add_replies_to_conv(conv, msgs) self.command.handle(self.user_email, 'stats', conv.key) output = self.command.stdout.getvalue().strip().split('\n') self.assertEqual(output, [ u'Conversation: active', u'Total Received in batch %s: 5' % (conv.batch.key, ), u'Total Sent in batch %s: 5' % (conv.batch.key, ), u'Total Uniques: 5', u'Received per date:', u'%s: 5' % (datetime.now().date(), ), u'Sent per date:', u'%s: 5' % (datetime.now().date(), ), ])
def setup_fix_batches(self, tags=(), num_batches=1): mdb = self.user_api.api.mdb msg_helper = GoMessageHelper() # We can't use .store_*(), so no mdb. batches = [mdb.batch_start(tags=tags) for i in range(num_batches)] conv = self.mkoldconv(create_batch=False, conversation_type=u'dummy_type', name=u'Dummy Conv 1', description=u'Dummy Description', config={}) for i, batch_id in enumerate(batches): conv.batches.add_key(batch_id) msg1 = msg_helper.make_inbound("in", message_id=u"msg-%d" % i) mdb.add_inbound_message(msg1, batch_id=batch_id) msg2 = msg_helper.make_outbound("out", message_id=u"msg-%d" % i) mdb.add_outbound_message(msg2, batch_id=batch_id) conv.save() return conv
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.user_helper = yield self.vumi_helper.make_user(u'username') self.msg_helper = self.add_helper( GoMessageHelper(vumi_helper=self.vumi_helper)) self.conv = yield self.user_helper.create_conversation(u'dummy') yield self.vumi_helper.setup_tagpool( u"pool", [u"tag%s" % (i, ) for i in range(1, 5)], metadata={ "display_name": "pool", "delivery_class": "sms", "transport_type": "sms", "transport_name": self.msg_helper.transport_name, }) yield self.user_helper.add_tagpool_permission(u"pool")
def __init__(self, worker_class, **msg_helper_args): self._worker_class = worker_class self.vumi_helper = VumiApiHelper() self._app_helper = ApplicationHelper(self._conversation_type(), self.vumi_helper) self.msg_helper = GoMessageHelper(**msg_helper_args) self.transport_name = self.msg_helper.transport_name self.worker_helper = self.vumi_helper.get_worker_helper( self.transport_name) self.dispatch_helper = MessageDispatchHelper(self.msg_helper, self.worker_helper) # Proxy methods from our helpers. generate_proxies(self, self._app_helper) generate_proxies(self, self.msg_helper) generate_proxies(self, self.worker_helper) generate_proxies(self, self.dispatch_helper)
def setUp(self): super(TestOptOutResource, self).setUp() self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.msg_helper = self.add_helper(GoMessageHelper()) self.user_helper = yield self.vumi_helper.make_user(u'user') user_account = yield self.user_helper.get_user_account() user_account.can_manage_optouts = True yield user_account.save() self.app_worker.user_api = self.user_helper.user_api self.contact_store = self.user_helper.user_api.contact_store self.optout_store = OptOutStore.from_user_account(user_account) yield self.create_resource({}) self.contact1 = yield self.new_contact(name=u'A', surname=u'Person', msisdn=u'+27123456789') self.contact2 = yield self.new_contact(name=u'B', surname=u'Person', msisdn=u'+27000000000')
class RouterWorkerHelper(object): implements(IHelper) def __init__(self, worker_class, **msg_helper_args): self._worker_class = worker_class msg_helper_kw = {} if msg_helper_args is not None: msg_helper_kw.update(msg_helper_args) self.vumi_helper = VumiApiHelper() self._router_helper = RouterHelper( self._router_type(), self.vumi_helper) self.msg_helper = GoMessageHelper(**msg_helper_kw) # Proxy methods from our helpers. generate_proxies(self, self._router_helper) generate_proxies(self, self.msg_helper) self.ri = RouterConnectorHelper( 'ri_conn', self.vumi_helper, self.msg_helper) self.ro = RouterConnectorHelper( 'ro_conn', self.vumi_helper, self.msg_helper) def _worker_name(self): return self._worker_class.worker_name def _router_type(self): # This is a guess based on worker_name. # We need a better way to do this. return self._worker_name().rpartition('_')[0].decode('utf-8') def setup(self): self.vumi_helper.setup(setup_vumi_api=False) @inlineCallbacks def cleanup(self): yield self.ro.cleanup() yield self.ri.cleanup() yield self.msg_helper.cleanup() yield self.vumi_helper.cleanup() @inlineCallbacks def get_router_worker(self, config=None, start=True): # Note: We assume that this is called exactly once per test. config = self.vumi_helper.mk_config(config or {}) config.setdefault('worker_name', self._worker_name()) config.setdefault('ri_connector_name', self.ri.connector_name) config.setdefault('ro_connector_name', self.ro.connector_name) worker = yield self.ri.get_worker(self._worker_class, config, start) # Set up our other bits of helper. self.vumi_helper.set_vumi_api(worker.vumi_api) self.msg_helper.mdb = worker.vumi_api.mdb returnValue(worker) @inlineCallbacks def start_router(self, router): assert self._get_pending_commands() == [], ( "Found pending commands while starting router, aborting.") user_helper = yield self.vumi_helper.get_or_create_user() router_api = user_helper.user_api.get_router_api( router.router_type, router.key) yield router_api.start_router(router) yield self.dispatch_commands_to_router() @inlineCallbacks def stop_router(self, router): assert self._get_pending_commands() == [], ( "Found pending commands while stopping router, aborting.") user_helper = yield self.vumi_helper.get_or_create_user() router_api = user_helper.user_api.get_router_api( router.router_type, router.key) yield router_api.stop_router(router) yield self.dispatch_commands_to_router() def _get_pending_commands(self): return self.ri.get_dispatched('vumi', 'api', VumiApiCommand) @inlineCallbacks def dispatch_commands_to_router(self): pending_commands = self._get_pending_commands() self.ri._worker_helper._clear_dispatched('vumi', 'api') for command in pending_commands: yield self.ri.dispatch_raw( "%s.control" % (self._worker_name(),), command) @inlineCallbacks def dispatch_command(self, command, *args, **kw): cmd = VumiApiCommand.command( self._worker_name(), command, *args, **kw) yield self.dispatch_raw('vumi.api', cmd) yield self.dispatch_commands_to_router() def get_published_metrics(self, worker): return [ (metric.name, value) for metric, ((time, value),) in worker.metrics._oneshot_msgs] def get_dispatched_router_events(self): return self.get_dispatched('vumi', 'event', VumiApiEvent)
def add_stored_replies(self, msgs): msg_helper = GoMessageHelper(vumi_helper=self.app_helper) conv = self.get_conversation() return msg_helper.add_replies_to_conv(conv, msgs)
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.user_helper = yield self.vumi_helper.make_user(u'user') user_account = yield self.user_helper.get_user_account() self.opt_out_store = OptOutStore.from_user_account(user_account) self.msg_helper = self.add_helper(GoMessageHelper())
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.user_helper = yield self.vumi_helper.get_or_create_user() self.msg_helper = yield self.add_helper( GoMessageHelper(self.vumi_helper))
def setUp(self): super(TestConversationViews, self).setUp() self.msg_helper = self.add_helper( GoMessageHelper(vumi_helper=self.vumi_helper))
def add_stored_inbound(self, count, **kw): msg_helper = GoMessageHelper(vumi_helper=self.app_helper) conv = self.get_conversation() return msg_helper.add_inbound_to_conv(conv, count, **kw)
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper()) self.msg_helper = self.add_helper( GoMessageHelper(vumi_helper=self.vumi_helper)) self.user_helper = yield self.vumi_helper.make_user(u'user') self.patch(time, 'time', lambda: 1985)
def setUp(self): self.vumi_helper = yield self.add_helper(VumiApiHelper(), setup_vumi_api=True) self.app_helper = self.add_helper( ApplicationHelper(u"dummy", self.vumi_helper)) self.msg_helper = self.add_helper(GoMessageHelper())
def add_stored_replies(self, msgs): msg_helper = GoMessageHelper(vumi_helper=self.router_helper) conv = self.get_router() return msg_helper.add_replies_to_conv(conv, msgs)
def setUp(self): self.vumi_helper = self.add_helper(DjangoVumiApiHelper()) self.user_helper = self.vumi_helper.make_django_user() self.msg_helper = self.add_helper( GoMessageHelper(vumi_helper=self.vumi_helper))
def add_stored_inbound(self, count, **kw): msg_helper = GoMessageHelper(vumi_helper=self.router_helper) conv = self.get_router() return msg_helper.add_inbound_to_conv(conv, count, **kw)