Not sure what I'm missing, below is the beginning of a test I'm working on. Would appreciate pointers on what I've left out.
The goal is to
- define a vocabulary as part of a behaviour
- assign the new behavior to a document
- then run tests against the document with the vocabulary
Basically I want to be able to add the behaviour in my test suite. Something like this:
doc_with_customvocab = IDummyVocabField(doc)
# then add my tests below
Here is where I've reached (I know it's incomplete and broken, I'm sharing with the hope of getting some guidance)
note that, in "real life" you would register a behaviour using zcml, I'm avoiding that approach in the test.
def test_human_readable_title(self):
self.assertEqual(len(self.collection.results()), 2)
from zope.interface import implementer
from zope.interface import Interface
from plone.app.contenttypes.content import Document
from plone.behavior.interfaces import IBehaviorAssignable
from zope.component import adapter
from zope.interface import implementer
# define the vocabulary
items = [ ('value1', u'Value 1 title'), ('value2', u'Value 2 title')]
terms = [ SimpleTerm(value=pair[0], token=pair[0], title=pair[1]) for pair in items ]
dummy_vocabulary = SimpleVocabulary(terms)
# Field with a vocabulary
@provider(IFormFieldProvider)
class IDummyVocabField(model.Schema):
dummy = schema.Choice(title=u"Dummy",
vocabulary=dummy_vocabulary
)
# register field as a behavior
from plone.behavior.registration import BehaviorRegistration
from zope.component import provideAdapter
registration = BehaviorRegistration(
title=u"Dummy Vocab Field",
description=u"Provides vocab field",
interface=IDummyVocabField,
marker=None,
factory=None)