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

Commit

Permalink
Add --switch-to-counters to message cache management command.
Browse files Browse the repository at this point in the history
  • Loading branch information
hodgestar committed Feb 18, 2014
1 parent 3464754 commit e836f08
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
11 changes: 10 additions & 1 deletion go/base/management/commands/go_manage_message_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class Command(BaseGoCommand):
help = "Manage the message cache."

option_list = BaseGoCommand.option_list + (
make_command_option('reconcile', help='Reconcile the message cache.'),
make_command_option(
'reconcile', help='Reconcile the message cache.'),
make_command_option(
'switch_to_counters', help='Switch cache to counters.'),
make_option(
'--email-address', dest='email_address',
help="Act on the given user's batches."),
Expand Down Expand Up @@ -64,3 +67,9 @@ def reconcile(user_api, batch_id):
user_api.api.mdb.reconcile_cache(batch_id)

self._apply_to_batches(reconcile)

def handle_command_switch_to_counters(self, *args, **options):
def switch_to_counters(user_api, batch_id):
user_api.api.mdb.cache.switch_to_counters(batch_id)

self._apply_to_batches(switch_to_counters)
21 changes: 21 additions & 0 deletions go/base/tests/test_go_manage_message_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def _assert_batches_recon_state(self, batches, recon_required):
def assert_batches_reconciled(self, batches):
self._assert_batches_recon_state(batches, False)

def uses_counters(self, batch_id):
vumi_api = self.vumi_helper.get_vumi_api()
return vumi_api.mdb.cache.uses_counters(batch_id)

def test_reconcile_conversation(self):
conv = self.user_helper.create_conversation(u"http_api")
self.clear_batches([conv.batch.key])
Expand Down Expand Up @@ -89,3 +93,20 @@ def test_reconcile_active_conversations_in_all_accounts(self):
expected_output, 'reconcile',
active_conversations=True)
self.assert_batches_reconciled(batch_ids)

def test_switch_to_counters(self):
conv = self.user_helper.create_conversation(u"http_api")
self.clear_batches([conv.batch.key])
self.assertFalse(self.uses_counters(conv.batch.key))
expected_output = "\n".join([
u'Processing account Test User'
u' <user@domain.com> [test-0-user] ...',
u' Performing switch_to_counters on'
u' batch %s ...' % conv.batch.key,
u'done.',
u''
])
self.assert_command_output(
expected_output, 'switch_to_counters',
email_address=self.user_email, conversation_key=conv.key)
self.assertTrue(self.uses_counters(conv.batch.key))

0 comments on commit e836f08

Please sign in to comment.