Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:praekelt/vumi into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Oct 8, 2013
2 parents 5552914 + 8d47587 commit 2069b09
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ install:
# We easy_install a binary riak_pb package because pip install needs `protoc'.
- "easy_install 'riak_pb<1.3.0'"
- "pip install -r requirements.pip --use-mirrors"
- "pip install coveralls --use-mirrors"
- "python setup.py install"
script: VUMITEST_REDIS_DB=1 trial vumi
script:
- VUMITEST_REDIS_DB=1 coverage run --source=vumi `which trial` vumi
after_success:
- coveralls
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Documentation available online at http://vumi.readthedocs.org/ and in the `docs`
.. |vumi-ci| image:: https://travis-ci.org/praekelt/vumi.png?branch=develop
.. _vumi-ci: https://travis-ci.org/praekelt/vumi

|vumi-cover|_

.. |vumi-cover| image:: https://coveralls.io/repos/praekelt/vumi/badge.png?branch=develop
.. _vumi-cover: https://coveralls.io/r/praekelt/vumi

To build the docs locally::

$ virtualenv --no-site-packages ve/
Expand Down
3 changes: 3 additions & 0 deletions vumi/scripts/model_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def run(self):
else:
keys = self.model.all_keys()
self.emit("%d keys found. Migrating ..." % len(keys))
# Depending on our Riak client, Python version, and JSON library we may
# get bytes or unicode here.
keys = [k.decode('utf-8') if isinstance(k, str) else k for k in keys]
progress = ProgressEmitter(
len(keys),
lambda p: self.emit("%s%% complete." % (p,))
Expand Down
4 changes: 2 additions & 2 deletions vumi/scripts/tests/test_model_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def tombstone_load(modelcls, key, result=None):
cfg = self.make_migrator()
cfg.run()
for i in range(3):
self.assertTrue(("Skipping tombstone key 'key-%d'." % i)
self.assertTrue(("Skipping tombstone key u'key-%d'." % i)
in cfg.output)
self.assertEqual(cfg.output[:1], [
"3 keys found. Migrating ...",
Expand All @@ -135,7 +135,7 @@ def error_load(modelcls, key, result=None):
line_pairs = zip(cfg.output, cfg.output[1:])
for i in range(3):
self.assertTrue((
"Failed to migrate key 'key-0':",
"Failed to migrate key u'key-0':",
" ValueError: Failed to load.",
) in line_pairs)
self.assertEqual(cfg.output[:1], [
Expand Down
31 changes: 31 additions & 0 deletions vumi/scripts/tests/test_vumi_tagpools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 @@ -167,3 +168,33 @@ def test_list_pools_with_all_sorts_of_pools(self):
'Pools only in tagpool:',
' other',
])


class ReleaseTagCmdTestCase(TagPoolBaseTestCase):

def setUp(self):
super(ReleaseTagCmdTestCase, self).setUp()
self.test_tags = [("foo", "tag%d" % i) for
i in [1, 2, 3, 5, 6, 7, 9]]

def test_release_tag_not_in_use(self):
cfg = make_cfg(["release-tag", "foo", "tag1"])
cfg.tagpool.declare_tags(self.test_tags)
cfg.run()
self.assertEqual(cfg.output,
["Tag ('foo', 'tag1') not in use."])

def test_release_unknown_tag(self):
cfg = make_cfg(["release-tag", "foo", "tag1"])
cfg.run()
self.assertEqual(cfg.output,
["Unknown tag ('foo', 'tag1')."])

def test_release_tag(self):
cfg = make_cfg(["release-tag", "foo", "tag1"])
cfg.tagpool.declare_tags(self.test_tags)
cfg.tagpool.acquire_specific_tag(('foo', 'tag1'))
self.assertEqual(cfg.tagpool.inuse_tags('foo'), [('foo', 'tag1')])
cfg.run()
self.assertEqual(cfg.tagpool.inuse_tags('foo'), [])
self.assertEqual(cfg.output, ["Released ('foo', 'tag1')."])
27 changes: 26 additions & 1 deletion vumi/scripts/vumi_tagpools.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,28 @@ def run(self, cfg):
or ['-- None --']))


class ReleaseTagCmd(usage.Options):

synopsis = "<pool> <tag>"

def parseArgs(self, pool, tag):
self.pool = pool
self.tag = tag

def run(self, cfg):
free_tags = cfg.tagpool.free_tags(self.pool)
inuse_tags = cfg.tagpool.inuse_tags(self.pool)
tag_tuple = (self.pool, self.tag)
if tag_tuple not in inuse_tags:
if tag_tuple not in free_tags:
cfg.emit('Unknown tag %s.' % (tag_tuple,))
else:
cfg.emit('Tag %s not in use.' % (tag_tuple,))
else:
cfg.tagpool.release_tag(tag_tuple)
cfg.emit('Released %s.' % (tag_tuple,))


class Options(usage.Options):
subCommands = [
["create-pool", None, CreatePoolCmd,
Expand All @@ -128,7 +150,10 @@ class Options(usage.Options):
"List the free and inuse keys associated with a tag pool."],
["list-pools", None, ListPoolsCmd,
"List all pools defined in config and in the tag store."],
]
["release-tag", None, ReleaseTagCmd,
"Release a single tag, moves it from the in-use to the free set. "
"Use only if you know what you are doing."]
]

optParameters = [
["config", "c", "tagpools.yaml",
Expand Down
2 changes: 1 addition & 1 deletion vumi/tests/test_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_basic_item(self):

def test_repr(self):
item = Mocking.HistoryItem(("a", "b"), {"c": 1})
self.assertEqual(repr(item), "<'HistoryItem' object at %s"
self.assertEqual(repr(item), "<'HistoryItem' object at %r"
" [args: ('a', 'b'), kw: {'c': 1}]>" % id(item))


Expand Down
10 changes: 5 additions & 5 deletions vumi/transports/imimobile/tests/test_imimobile_ussd.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ def test_request_with_unexpected_parameters(self):
response = yield self.mk_request(
'some-suffix', unexpected_p1='', unexpected_p2='')

self.assertEqual(
response.delivered_body,
json.dumps({
'unexpected_parameter': ['unexpected_p1', 'unexpected_p2']
}))
self.assertEqual(response.code, 400)
body = json.loads(response.delivered_body)
self.assertEqual(set(['unexpected_parameter']), set(body.keys()))
self.assertEqual(
sorted(body['unexpected_parameter']),
['unexpected_p1', 'unexpected_p2'])

@inlineCallbacks
def test_nack_insufficient_message_fields(self):
Expand Down

0 comments on commit 2069b09

Please sign in to comment.