Skip to content

Commit

Permalink
Add utils test / fix unicode bug in utils.
Browse files Browse the repository at this point in the history
  • Loading branch information
jone committed Feb 27, 2012
1 parent 29ccb21 commit 65df85e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -6,5 +6,7 @@
.mr.developer.cfg
bin/
buildout.cfg
coverage/
develop-eggs/
parts/
var/
60 changes: 60 additions & 0 deletions ftw/tagging/tests/test_utils.py
@@ -0,0 +1,60 @@
from ftw.tagging import utils
from ftw.tagging.interfaces.tagging import ITaggable, ITagRoot
from ftw.testing import MockTestCase


class TestUtils(MockTestCase):

def setUp(self):
portal_url = self.stub()
self.mock_tool(portal_url, 'portal_url')
self.portal = self.stub()
self.expect(portal_url.getPortalObject()).result(self.portal)

def test_getInterfaceRoot(self):
root = self.providing_stub([ITagRoot])

obj = self.set_parent(
self.stub(),
self.set_parent(
self.stub(),
self.set_parent(
root,
self.portal)))

self.replay()

self.assertEqual(utils.getInterfaceRoot(obj, ITagRoot), root)

def test_getInterfaceRoot_when_root_reached(self):
obj = self.set_parent(
self.stub(),
self.portal)

self.replay()

self.assertEqual(utils.getInterfaceRoot(obj, ITagRoot), self.portal)


def test_getTagRootTags(self):
brain1 = self.stub()
self.expect(brain1.tags).result(('foo', 'bar', u'\xe4', '\xc3\xa4'))
brain2 = self.stub()
self.expect(brain2.tags).result(('bar', u'baz'))
brain3 = self.stub()
self.expect(brain3.tags).result(None)

root = self.providing_stub([ITagRoot])
obj = self.set_parent(self.stub(), root)
self.expect(root.getPhysicalPath()).result(['', 'path', 'to', 'root'])

catalog = self.stub()
self.mock_tool(catalog, 'portal_catalog')
query = {'path': '/path/to/root',
'object_provides': ITaggable.__identifier__}
self.expect(catalog(query)).result([brain1, brain2])

self.replay()

self.assertEqual(set(utils.getTagRootTags(obj)),
set(['foo', 'bar', 'baz', '\xc3\xa4']))
3 changes: 2 additions & 1 deletion ftw/tagging/utils.py
Expand Up @@ -42,7 +42,8 @@ def getTagRootTags(context):
if not isinstance(tags, tuple):
continue
for tag in tags:
tag = tag.encode('utf-8')
if isinstance(tag, unicode):
tag = tag.encode('utf-8')
items.add(tag)

return list(items)
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Expand Up @@ -6,6 +6,8 @@

tests_require = [
'collective.testcaselayer',
'Products.PloneTestCase',
'ftw.testing',
]


Expand Down

0 comments on commit 65df85e

Please sign in to comment.