Permalink
Browse files

Add utils test / fix unicode bug in utils.

  • Loading branch information...
1 parent 29ccb21 commit 65df85e6630e1c4e96dffd892d50819fbfafce6c @jone jone committed Feb 27, 2012
Showing with 66 additions and 1 deletion.
  1. +2 −0 .gitignore
  2. +60 −0 ftw/tagging/tests/test_utils.py
  3. +2 −1 ftw/tagging/utils.py
  4. +2 −0 setup.py
View
2 .gitignore
@@ -6,5 +6,7 @@
.mr.developer.cfg
bin/
buildout.cfg
+coverage/
develop-eggs/
parts/
+var/
View
60 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']))
View
3 ftw/tagging/utils.py
@@ -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)
View
2 setup.py
@@ -6,6 +6,8 @@
tests_require = [
'collective.testcaselayer',
+ 'Products.PloneTestCase',
+ 'ftw.testing',
]

0 comments on commit 65df85e

Please sign in to comment.