Skip to content

Commit

Permalink
Merge branch 'feature/issue-625-add-tagpools-metadata-bulk-updater' i…
Browse files Browse the repository at this point in the history
…nto develop
  • Loading branch information
hodgestar committed Oct 14, 2013
2 parents 0b8c1a7 + 81ecc6a commit 14ab507
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
33 changes: 31 additions & 2 deletions vumi/scripts/tests/test_vumi_tagpools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pkg_resources import resource_filename

from twisted.trial.unittest import TestCase
from twisted.python import usage

from vumi.tests.utils import PersistenceMixin

Expand Down Expand Up @@ -71,7 +70,7 @@ def test_create_pool_explicit_tags(self):


class UpdatePoolMetadataCmdTestCase(TagPoolBaseTestCase):
def test_create_pool_range_tags(self):
def test_update_tagpool_metadata(self):
cfg = make_cfg(["update-pool-metadata", "shortcode"])
cfg.run()
self.assertEqual(cfg.output, [
Expand All @@ -82,6 +81,36 @@ def test_create_pool_range_tags(self):
{'transport_type': 'sms'})


class UpdateAllPoolMetadataCmdTestCase(TagPoolBaseTestCase):
def test_update_all_metadata(self):
cfg = make_cfg(["update-all-metadata"])
cfg.tagpool.declare_tags([("xmpp", "tag"), ("longcode", "tag")])
cfg.run()
self.assertEqual(cfg.output, [
'Updating pool metadata.',
'Note: Pools not present in both the config and tagpool'
' store will not be updated.',
' Updating metadata for pool longcode ...',
' Updating metadata for pool xmpp ...',
'Done.'
])
self.assertEqual(cfg.tagpool.get_metadata("longcode"),
{u'transport_type': u'sms'})
self.assertEqual(cfg.tagpool.get_metadata("xmpp"),
{u'transport_type': u'xmpp'})
self.assertEqual(cfg.tagpool.get_metadata("shortcode"), {})

def test_no_pools(self):
cfg = make_cfg(["update-all-metadata"])
cfg.run()
self.assertEqual(cfg.output, [
'Updating pool metadata.',
'Note: Pools not present in both the config and tagpool'
' store will not be updated.',
'No pools found.',
])


class PurgePoolCmdTestCase(TagPoolBaseTestCase):
def test_purge_pool(self):
cfg = make_cfg(["purge-pool", "foo"])
Expand Down
24 changes: 24 additions & 0 deletions vumi/scripts/vumi_tagpools.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@ def run(self, cfg):
cfg.emit(" Done.")


class UpdateAllPoolMetadataCmd(usage.Options):
def run(self, cfg):
pools_in_tagpool = cfg.tagpool.list_pools()
pools_in_cfg = set(cfg.pools.keys())
pools_in_both = sorted(pools_in_tagpool.intersection(pools_in_cfg))

cfg.emit("Updating pool metadata.")
cfg.emit("Note: Pools not present in both the config and tagpool"
" store will not be updated.")

if not pools_in_both:
cfg.emit("No pools found.")
return

for pool in pools_in_both:
cfg.emit(" Updating metadata for pool %s ..." % pool)
metadata = cfg.metadata(pool)
cfg.tagpool.set_metadata(pool, metadata)

cfg.emit("Done.")


class PurgePoolCmd(PoolSubCmd):
def run(self, cfg):
cfg.emit("Purging pool %s ..." % self.pool)
Expand Down Expand Up @@ -144,6 +166,8 @@ class Options(usage.Options):
"Declare tags for a tag pool."],
["update-pool-metadata", None, UpdatePoolMetadataCmd,
"Update a pool's metadata from config."],
["update-all-metadata", None, UpdateAllPoolMetadataCmd,
"Update all pool meta data from config."],
["purge-pool", None, PurgePoolCmd,
"Purge all tags from a tag pool."],
["list-keys", None, ListKeysCmd,
Expand Down

0 comments on commit 14ab507

Please sign in to comment.