Skip to content

Commit

Permalink
- set up the vocabulary storage
Browse files Browse the repository at this point in the history
 - write test for storage creation
 - fix test for event handler


git-svn-id: https://svn.plone.org/svn/collective/collective.vocabularymanager/trunk@239744 db7f04ef-aaf3-0310-a811-c281ed44c4ad
  • Loading branch information
claytron committed May 20, 2011
1 parent 001482e commit 6f7f6a8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
32 changes: 26 additions & 6 deletions collective/vocabularymanager/tests/test_vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,37 @@
from collective.vocabularymanager.tests.base import VMTestCase
from zope.component.interface import provideInterface


class MockVocabEventHandler(object):

def __init__(self):
self.object = None
self.event = None

def __call__(self, object, event):
self.object = object
self.event = event


class TestVocabularyManager(VMTestCase):

def test_event_is_fired_when_vocabulary_deleted(self):
remove_id = False
def event_handler(object, event):
remove_id = event.vocab_id
event_handler = MockVocabEventHandler()
gsm = getGlobalSiteManager()
gsm.registerHandler(event_handler, (IVocabularyUtility, IVocabularyRemovedEvent), u'')
gsm.registerHandler(
event_handler,
(IVocabularyUtility, IVocabularyRemovedEvent),
u'')
util = VocabularyUtility()
util.remove_vocab('foo')
self.failUnless(remove_id == 'foo')
self.failUnless(event_handler.event.vocab_id == 'foo')

def test_storage_creation(self):
self.failIf(hasattr(self.layer['portal'], '_vocabularies_'))
vm = getUtility(IVocabularyUtility)
vm()
self.failUnless(hasattr(self.layer['portal'], '_vocabularies_'))


def test_suite():
"""This sets up a test suite that actually runs the tests in the class
Expand Down
8 changes: 8 additions & 0 deletions collective/vocabularymanager/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
from collective.vocabularymanager.events import VocabularyRemovedEvent
from zope.interface import implements
from zope.event import notify
from zope.app.component.hooks import getSite
from zope.container.ordered import OrderedContainer


class VocabularyUtility(object):
implements(IVocabularyUtility)

def __init__(self):
portal = getSite()
if not hasattr(portal, '_vocabularies_'):
setattr(portal, '_vocabularies_', OrderedContainer())
self.storage = portal._vocabularies_

def add_term(self, vocab_id, term):
pass

Expand Down

0 comments on commit 6f7f6a8

Please sign in to comment.