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

Commit

Permalink
Merge branch 'develop' into feature/issue-1127-support-managing-opt-o…
Browse files Browse the repository at this point in the history
…uts-for-accounts
  • Loading branch information
justinvdm committed Jan 6, 2015
2 parents 357a7e0 + a9913ab commit d47946d
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 67 deletions.
7 changes: 5 additions & 2 deletions go/account/tests.py
Expand Up @@ -229,11 +229,14 @@ def test_daily_account_summary(self):
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)

# TODO fix once we support uniques properly again
self.assertTrue('Sent: 5 to 0 uniques.' in email.body)
self.assertTrue('Received: 5 from 0 uniques.' in email.body)


def test_send_scheduled_account_summary_task(self):
user_account = self.user_helper.get_user_account()
user_account.email_summary = u'daily'
Expand Down
6 changes: 4 additions & 2 deletions go/apps/jsbox/tests/test_message_store.py
Expand Up @@ -85,13 +85,15 @@ def test_handle_count_sent_messages(self):
def test_handle_count_inbound_uniques(self):
reply = yield self.dispatch_command('count_inbound_uniques')
self.assertTrue(reply['success'])
self.assertEqual(reply['count'], 1)
# TODO fix once we support uniques properly again
self.assertEqual(reply['count'], 0)

@inlineCallbacks
def test_handle_count_outbound_uniques(self):
reply = yield self.dispatch_command('count_outbound_uniques')
self.assertTrue(reply['success'])
self.assertEqual(reply['count'], 1)
# TODO fix once we support uniques properly again
self.assertEqual(reply['count'], 0)

@inlineCallbacks
def test_handle_inbound_throughput(self):
Expand Down
25 changes: 1 addition & 24 deletions go/apps/sequential_send/tests/test_vumi_app.py
Expand Up @@ -198,29 +198,6 @@ def test_get_conversations(self):
self.assertEqual(sorted([c.key for c in convs]),
sorted([conv1.key, conv2.key]))

@inlineCallbacks
def test_get_conversations_batch_key(self):
"""
Test get_conversation using the batch key fallback.
"""

conv1 = yield self.app_helper.create_conversation(
config={'schedule': {'recurring': 'daily', 'time': '00:01:40'}})
yield self.app_helper.start_conversation(conv1)

conv2 = yield self.app_helper.create_conversation(
config={'schedule': {'recurring': 'daily', 'time': '00:02:30'}})
yield self.app_helper.start_conversation(conv2)

yield self.app_helper.create_conversation(
config={'schedule': {'recurring': 'daily', 'time': '00:02:30'}})

convs = yield self.app.get_conversations(
[[conv1.batch.key, conv1.key], [conv2.batch.key, conv2.key]])

self.assertEqual(sorted([c.key for c in convs]),
sorted([conv1.key, conv2.key]))

@inlineCallbacks
def test_get_conversations_missing_conv(self):
"""
Expand All @@ -233,7 +210,7 @@ def test_get_conversations_missing_conv(self):

with LogCatcher(message='Conversation .* not found.') as lc:
convs = yield self.app.get_conversations(
[[conv.batch.key, conv.key], ['badaccount', 'badkey']])
[[conv.user_account.key, conv.key], ['badaccount', 'badkey']])
self.assertEqual(
lc.messages(),
['Conversation badkey for account badaccount not found.'])
Expand Down
26 changes: 1 addition & 25 deletions go/apps/sequential_send/vumi_app.py
Expand Up @@ -86,7 +86,7 @@ def get_interval(self):
@inlineCallbacks
def get_conversations(self, conv_pointers):
results = yield gatherResults([
self.get_conversation_fallback(account_key, conv_key)
self.get_conversation(account_key, conv_key)
for account_key, conv_key in conv_pointers])
conversations = []
for pointer, conv in zip(conv_pointers, results):
Expand All @@ -97,30 +97,6 @@ def get_conversations(self, conv_pointers):
conversations.append(conv)
returnValue(conversations)

@inlineCallbacks
def get_conversation_fallback(self, account_key_or_batch_id, conv_key):
# HACK: If we can't find a conversation, we might have an old entry
# that uses a batch_id.
conv = yield self.get_conversation(account_key_or_batch_id, conv_key)
if conv is None:
log.info("Trying to find conversation '%s' by batch_id." % (
conv_key,))
batch = yield self.vumi_api.mdb.get_batch(account_key_or_batch_id)
if batch is None:
log.warning('Cannot find batch for batch_id %s' % (
account_key_or_batch_id,))
return
user_account_key = batch.metadata["user_account"]
if user_account_key is None:
log.warning("No account key in batch metadata: %r" % (batch,))
return
yield self.redis.srem('scheduled_conversations', json.dumps(
[account_key_or_batch_id, conv_key]))
yield self.redis.sadd('scheduled_conversations', json.dumps(
[user_account_key, conv_key]))
conv = yield self.get_conversation(user_account_key, conv_key)
returnValue(conv)

def _get_scheduled_conversations(self):
return self.redis.smembers('scheduled_conversations')

Expand Down
8 changes: 5 additions & 3 deletions go/base/tests/test_go_system_stats.py
Expand Up @@ -163,13 +163,15 @@ def test_message_counts_by_month(self):
)

cmd = self.run_command(command=["message_counts_by_month"])

# TODO fix once we support uniques properly again
self.assert_csv_output(cmd, [
"date,conversations_started,"
"inbound_message_count,outbound_message_count,"
"inbound_uniques,outbound_uniques,total_uniques",
"09/01/2013,1,3,6,1,2,2",
"11/01/2013,3,2,2,2,2,2",
"12/01/2013,2,4,6,2,6,6",
"09/01/2013,1,3,6,0,0,0",
"11/01/2013,3,2,2,0,0,0",
"12/01/2013,2,4,6,0,0,0",
])

def test_custom_date_format(self):
Expand Down
8 changes: 4 additions & 4 deletions go/conversation/tests.py
Expand Up @@ -720,8 +720,8 @@ def test_message_list_inbound_uniques_display(self):
conv = self.user_helper.create_conversation(u'dummy', started=True)
msgs = self.msg_helper.add_inbound_to_conv(conv, 10)
response = self.client.get(self.get_view_url(conv, 'message_list'))
self.assertContains(
response, 'Messages from 10 unique people')
# TODO fix once we support uniques properly again
self.assertContains(response, 'Messages from 0 unique people')

def test_message_list_inbound_download_links_display(self):
conv = self.user_helper.create_conversation(u'dummy', started=True)
Expand All @@ -743,8 +743,8 @@ def test_message_list_outbound_uniques_display(self):
self.get_view_url(conv, 'message_list'), {
'direction': 'outbound'
})
self.assertContains(
response, 'Messages to 10 unique people')
# TODO fix once we support uniques properly again
self.assertContains(response, 'Messages to 0 unique people')

def test_message_list_outbound_download_links_display(self):
conv = self.user_helper.create_conversation(u'dummy', started=True)
Expand Down
2 changes: 1 addition & 1 deletion go/vumitools/account/tests/test_models.py
Expand Up @@ -28,7 +28,7 @@ def store_user_version(self, version):
# Configure the manager to save the older message version.
modelcls = self.store.users._modelcls
model_name = "%s.%s" % (modelcls.__module__, modelcls.__name__)
self.store.manager.store_versions[model_name] = 4
self.store.manager.store_versions[model_name] = version

def assert_user(self, user, **fields):
def assert_field(value, name, default):
Expand Down
14 changes: 8 additions & 6 deletions go/vumitools/conversation/tests/test_utils.py
Expand Up @@ -82,23 +82,25 @@ def test_outbound_keys(self):

@inlineCallbacks
def test_count_inbound_uniques(self):
# TODO fix once we support uniques properly again
yield self.conv.start()
yield self.msg_helper.add_inbound_to_conv(self.conv, 3)
self.assertEqual((yield self.conv.count_inbound_uniques()), 3)
self.assertEqual((yield self.conv.count_inbound_uniques()), 0)
yield self.msg_helper.add_inbound_to_conv(self.conv, 4)
self.assertEqual((yield self.conv.count_inbound_uniques()), 4)
self.assertEqual((yield self.conv.count_inbound_uniques()), 0)
yield self.msg_helper.add_inbound_to_conv(self.conv, 2)
self.assertEqual((yield self.conv.count_inbound_uniques()), 4)
self.assertEqual((yield self.conv.count_inbound_uniques()), 0)

@inlineCallbacks
def test_count_outbound_uniques(self):
# TODO fix once we support uniques properly again
yield self.conv.start()
yield self.msg_helper.add_outbound_to_conv(self.conv, 3)
self.assertEqual((yield self.conv.count_outbound_uniques()), 3)
self.assertEqual((yield self.conv.count_outbound_uniques()), 0)
yield self.msg_helper.add_outbound_to_conv(self.conv, 4)
self.assertEqual((yield self.conv.count_outbound_uniques()), 4)
self.assertEqual((yield self.conv.count_outbound_uniques()), 0)
yield self.msg_helper.add_outbound_to_conv(self.conv, 2)
self.assertEqual((yield self.conv.count_outbound_uniques()), 4)
self.assertEqual((yield self.conv.count_outbound_uniques()), 0)

@inlineCallbacks
def test_received_messages(self):
Expand Down

0 comments on commit d47946d

Please sign in to comment.