def test_ext_dict_sets_parent_on_replacement_value(self): class InnerDict(object): def toExternalObject(self, **_kw): return {'key': 42} class InnerList(object): def toExternalObject(self, **_kw): return [76] inst = self._makeOne() inst.ivar = [InnerDict(), InnerList()] inst.dict = InnerDict() inst.list = InnerList() result = inst.toExternalDictionary() assert_that( result, is_({ u'Class': 'IO', 'ivar': [{ 'key': 42 }, [76]], 'dict': { 'key': 42 }, 'list': [76], })) assert_that(result['ivar'], has_property('__parent__', inst)) assert_that(result['ivar'][0], does_not(has_property('__parent__', inst))) assert_that(result['ivar'][1], does_not(has_property('__parent__', inst))) assert_that(result['dict'], does_not(has_property('__parent__', inst))) assert_that(result['list'], does_not(has_property('__parent__', inst)))
def test_provides_history_free(self): storage = self.makeOne(keep_history=False) assert_that(storage, validly_provides(IRelStorage)) assert_that(storage, does_not(provides(IStorageUndoable))) assert_that(storage, does_not(provides(IExternalGC))) assert_that(storage, does_not(provides(IBlobStorage))) assert_that(storage, does_not(provides(IBlobStorageRestoreable))) assert_that(storage, does_not(validly_provides(IExternalGC)))
def test_does_nothing_if_mimeType_present(self): class IExt(interface.Interface): interface.taggedValue('__external_class_name__', 'Ext') @interface.implementer(IExt) class E(object): mimeType = 'foo' AutoPackage._ap_handle_one_potential_factory_class(E, 'nti.package', E) assert_that(E, has_property("mimeType", 'foo')) assert_that(E, does_not(has_property("mime_type"))) assert_that(E, does_not(implements(IContentTypeAware))) del E.E
def test_adjust_interface_blank(self): # Initially, nothing adjust(self.request) assert_that(self.request, does_not(provides(IPreferredLanguagesRequest))) assert_that(self._langs(), is_empty()) assert_that(self._locale(), is_('en'))
def test_viewlet_manager_in_same_zcml(self): assert_that(viewlets, does_not(has_property('ILeftColumn'))) zcml = """ <configure xmlns="http://namespaces.zope.org/zope" xmlns:browser="http://namespaces.zope.org/browser"> <include package="nti.nikola_chameleon" file="meta.zcml" /> <include package="zope.viewlet" file="meta.zcml" /> <browser:newViewletManager id="ILeftColumn" /> <browser:viewletManager name="left_column" provides="nti.nikola_chameleon.viewlets.ILeftColumn" permission="zope.Public" /> </configure> """ xmlconfig.string(zcml) assert_that(viewlets, has_property('ILeftColumn')) context = object() from zope.publisher.browser import TestRequest request = TestRequest() from zope.publisher.browser import BrowserView view = BrowserView(context, request) import zope.component from zope.viewlet import interfaces zope.component.getMultiAdapter((context, request, view), interfaces.IViewletManager, name='left_column') zope.component.getMultiAdapter((context, request, view), viewlets.ILeftColumn, name='left_column')
def test_provides(self): cat = self._makeOne() assert_that(type(cat), implements(self.main_interface)) assert_that(cat, validly_provides(self.main_interface)) assert_that(cat, validly_provides(*self.extra_interfaces)) assert_that( cat, does_not(verifiably_provides(*self.doesnt_provide_interfaces)))
def test_inherits_external_can_create(self): class IExt(interface.Interface): interface.taggedValue('__external_class_name__', 'Ext') class Base(object): __external_can_create__ = False @interface.implementer(IExt) class E(Base): pass AutoPackage._ap_handle_one_potential_factory_class(E, 'nti.package', E) assert_that(E, has_property('__external_can_create__', False)) assert_that(E.__dict__, does_not(has_key('__external_can_create__')))
def test_adjust_interface_blank(self): # Initially, nothing adjust(self.request) assert_that(self.request, does_not(provides(IPreferredLanguagesRequest)))