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

Commit

Permalink
Remove unnecessary caching of get_tag_info.
Browse files Browse the repository at this point in the history
  • Loading branch information
jerith committed Jul 2, 2015
1 parent 5d8ef7e commit 19c1da7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 39 deletions.
2 changes: 1 addition & 1 deletion go/vumitools/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def get_config(self, msg):
if msg_mdh.has_user_account():
user_account_key = msg_mdh.get_account_key()
elif msg_mdh.tag is not None:
tag_info = yield msg_mdh.get_tag_info()
tag_info = yield self.vumi_api.mdb.get_tag_info(msg_mdh.tag)
user_account_key = tag_info.metadata['user_account']
if user_account_key is None:
raise UnownedTagError(
Expand Down
31 changes: 0 additions & 31 deletions go/vumitools/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,8 @@ def test_clear_object_cache(self):
md.set_tag(["pool", "tag"])
self.assertEqual(md._store_objects, {})
md_conv = yield md.get_conversation()
tag_info = yield md.get_tag_info()
self.assertEqual(md._store_objects, {
'conversation': md_conv,
'tag_info': tag_info,
})
md.clear_object_cache()
self.assertEqual(md._store_objects, {})
Expand Down Expand Up @@ -459,40 +457,11 @@ def test_rewrap(self):
self.assertEqual({}, other_md._store_objects)
self.assertEqual(md._go_metadata, other_md._go_metadata)

def test_get_tag_info_no_tag(self):
md = self.mk_md()
self.assertEqual(None, md.tag)
self.assertRaises(ValueError, md.get_tag_info)

def test_get_tagpool_metadata_no_tag(self):
md = self.mk_md()
self.assertEqual(None, md.tag)
self.assertRaises(ValueError, md.get_tagpool_metadata)

@inlineCallbacks
def test_get_tag_info(self):
md = self.mk_md()
md.set_tag(["pool", "tagname"])

tag_info = yield md.get_tag_info()
self.assertEqual(("pool", "tagname"), tag_info.tag)

@inlineCallbacks
def test_tag_info_caching(self):
md = self.mk_md()
md.set_tag(["pool", "tagname"])

self.assertEqual({}, md._store_objects)
tag_info = yield md.get_tag_info()
self.assertEqual(("pool", "tagname"), tag_info.tag)
self.assertEqual({'tag_info': tag_info}, md._store_objects)

# Stash a fake thing in the cache to make sure that what we get is
# actually the thing in the cache.
md._store_objects['tag_info'] = "I am the cached tag_info"
cached_tag_info = yield md.get_tag_info()
self.assertEqual(cached_tag_info, "I am the cached tag_info")

@inlineCallbacks
def test_get_tagpool_metadata(self):
yield self.vumi_helper.setup_tagpool("pool", ["tagname"], metadata={
Expand Down
7 changes: 0 additions & 7 deletions go/vumitools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ def set_tag(self, tag):
TaggingMiddleware.add_tag_to_msg(self.message, tag)
self.tag = TaggingMiddleware.map_msg_to_tag(self.message)

def get_tag_info(self):
if self.tag is None:
raise ValueError("No tag to look up metadata for.")

return self._get_if_not_stashed(
'tag_info', self.vumi_api.mdb.get_tag_info, tuple(self.tag))

def get_tagpool_metadata(self):
if self.tag is None:
raise ValueError("No tag to look up metadata for.")
Expand Down

0 comments on commit 19c1da7

Please sign in to comment.