Skip to content
This repository has been archived by the owner on Jun 12, 2018. It is now read-only.

Commit

Permalink
Construct vumi_username correctly in RapidSMS vumi_app.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Jan 10, 2014
1 parent 193b0e2 commit 2d95804
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions go/apps/rapidsms/tests/test_vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ class RapidSMSApplicationTestCase(VumiTestCase):
def setUp(self):
self.app_helper = self.add_helper(AppWorkerHelper(RapidSMSApplication))

def _username_for_conv(self, conv):
return RapidSMSApplication.vumi_username_for_conversation(conv)

@inlineCallbacks
def test_setup_application(self):
app = yield self.app_helper.get_app_worker(self.APP_CONFIG)
Expand All @@ -82,6 +85,7 @@ def test_get_config_for_message(self):
msg = yield self.app_helper.make_stored_inbound(conv, "foo")
config = yield app.get_config(msg)
self.assertTrue(isinstance(config, RapidSMSConfig))
self.assertEqual(config.vumi_username, self._username_for_conv(conv))

@inlineCallbacks
def test_get_config_for_username(self):
Expand All @@ -92,6 +96,7 @@ def test_get_config_for_username(self):
username="%s:%s" % (conv.user_account.key, conv.key))
config = yield app.get_config(None, ctxt=ctxt)
self.assertTrue(isinstance(config, RapidSMSConfig))
self.assertEqual(config.vumi_username, self._username_for_conv(conv))

@inlineCallbacks
def test_process_command_start(self):
Expand Down
7 changes: 6 additions & 1 deletion go/apps/rapidsms/vumi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@ def teardown_application(self):
yield super(RapidSMSApplication, self).teardown_application()
yield self._go_teardown_worker()

@staticmethod
def vumi_username_for_conversation(conversation):
return "%s:%s" % (conversation.user_account.key, conversation.key)

def get_config_data_for_conversation(self, conversation):
dynamic_config = conversation.config.get('rapidsms', {}).copy()
dynamic_config["vumi_auth_method"] = "basic"
dynamic_config["vumi_username"] = conversation.key
dynamic_config["vumi_username"] = self.vumi_username_for_conversation(
conversation)
auth_config = conversation.config.get('auth_tokens', {})
api_tokens = auth_config.get("api_tokens", [])
dynamic_config["vumi_password"] = api_tokens[0] if api_tokens else None
Expand Down

0 comments on commit 2d95804

Please sign in to comment.