def setUp(self):
        placelesssetup.setUp(self)

        self.configuration = GlobalConfiguration(
            subscriber_name_xpath=u'',
            add_subscriber_preferences=False,
            subscriber_preferences_url_xpath=u'',
            subscriber_preferences_html=u'',
            add_subscriber_removal=True,
            subscriber_removal_url_xpath=u'',
            subscriber_removal_html=u'',
            inline_styles=False,
        )
        zope.component.provideUtility(self.configuration)

        self.newsletter_attributes = stubydoo.double()
        self.context = stubydoo.double()
        request = object()
        self.newsletter = newsletter.Newsletter(self.context,
                                                request,
                                                self.newsletter_attributes)

        self.message_factory = stubydoo.double(__call__=lambda x, c: c)

        @zope.component.adapter(None, None, None, None)
        @zope.interface.implementer(interfaces.IMessageFactory)
        def message_factory_factory(context, request, newsletter, subscriber):
            return self.message_factory

        zope.component.provideAdapter(message_factory_factory)
Example #2
0
    def setUp(self):
        placelesssetup.setUp(self)

        self.mailhost = stubydoo.double()

        class IPossibleSubscriberProvider(zope.interface.Interface):
            pass
        self.subscriber = stubydoo.double()
        self.subscribers = [self.subscriber]
        self.newsletter = stubydoo.double()
        self.message = stubydoo.double()

        stubydoo.stub(self.newsletter, 'compile').with_args(self.subscriber).\
            and_return(self.message)
        stubydoo.stub(self.mailhost, 'send').with_args(self.message)

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.INewsletter)
        def newsletter_adapter(context):
            self.newsletter.context = context
            return self.newsletter
        zope.component.provideAdapter(newsletter_adapter)

        self.context = stubydoo.double()
        self.mailing = mailing.Mailing()
    def setUp(self):
        placelesssetup.setUp(self)

        self.configuration = GlobalConfiguration(
            subscriber_name_xpath=u'',
            add_subscriber_preferences=False,
            subscriber_preferences_url_xpath=u'',
            subscriber_preferences_html=u'',
            add_subscriber_removal=True,
            subscriber_removal_url_xpath=u'',
            subscriber_removal_html=u'',
            inline_styles=False,
        )
        zope.component.provideUtility(self.configuration)

        self.newsletter_attributes = stubydoo.double()
        self.context = stubydoo.double()
        request = object()
        self.newsletter = newsletter.Newsletter(self.context, request,
                                                self.newsletter_attributes)

        self.message_factory = stubydoo.double(__call__=lambda x, c: c)

        @zope.component.adapter(None, None, None, None)
        @zope.interface.implementer(interfaces.IMessageFactory)
        def message_factory_factory(context, request, newsletter, subscriber):
            return self.message_factory

        zope.component.provideAdapter(message_factory_factory)
    def test_compilation_with_default_xpath_and_css(self):
        context = double()
        configuration = double(
            xpath=NullTemplateConfiguration.xpath,
            css=NullTemplateConfiguration.css,
            html=u'<html><body></body></html>'
        )

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.IHTMLBody)
        def body_adapter(context):
            return double(__unicode__=lambda self:u'<p>Hello</p>')
        zope.component.provideAdapter(body_adapter)

        expected_body = u'<body><p>Hello</p></body>'

        strategy = CompilationStrategy(context, configuration)
        result = strategy.compile()
        resulting_body = lxml.html.document_fromstring(result).\
                xpath(u'//body')[0]

        self.assertEquals(
            expected_body,
            lxml.html.tostring(resulting_body)
        )
    def setUp(self):
        placelesssetup.setUp(self)
        self.config = stubydoo.double()

        # This kind of document uses a rich text field, which has an output
        # attribute.
        self.document = stubydoo.double(body=stubydoo.double())
        self.document.body = u'<p>Test!</p>'

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.IHTMLBody)
        def html_body(doc):
            return doc.body
        zope.component.provideAdapter(html_body)

        self.compiler = StyledPageCompilationStrategy(self.document, self.config)

        # This 'stubbing' relies on the fact that the function is accessed
        # through module's getattr always, no references kept.
        from tn.plonestyledpage import styled_page
        self.old_getUniqueId = styled_page.getUniqueId
        styled_page.getUniqueId = lambda page: u'foo'

        self.old_getEscapedStyleBlock = styled_page.getEscapedStyleBlock
        styled_page.getEscapedStyleBlock = lambda page: u'<style>%s</style>' % page.styles

        self.document.styles = u'p{color:red}'
Example #6
0
    def test_delegates_to_adapters(self):
        context = double()
        content = double(body=u'body')
        zope.interface.alsoProvides(context, IAttributeAnnotatable)

        template = Template(context)

        self.assertEquals(template.compile(content), u'html(body)')
    def test_traversing_to_a_unknown_key_redirects(self):
        response = double(redirect=lambda self, url:None)
        request = double(response=response)
        expect(response.redirect).with_args('the original url')

        cache_keys = zope.component.getUtility(interfaces.ICacheKeys)
        stub(cache_keys.getURL).with_args('unknown key').\
                and_return('the original url')

        self.cache_traverser.publishTraverse(request, 'unknown key')
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = stubydoo.double()
        self.adapted = stubydoo.double()

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.INewsletterAttributes)
        def newsletter_attributes_adapter(obj):
            return self.adapted
        zope.component.provideAdapter(newsletter_attributes_adapter)
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = stubydoo.double()
        self.adapted = stubydoo.double()

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.INewsletterAttributes)
        def newsletter_attributes_adapter(obj):
            return self.adapted

        zope.component.provideAdapter(newsletter_attributes_adapter)
Example #10
0
    def setUp(self):
        placelesssetup.setUp(self)

        self.metadata = double(language='klingon')

        @zope.component.adapter(None)
        @zope.interface.implementer(ICategorization)
        def metadata(context):
            return self.metadata
        zope.component.provideAdapter(metadata)

        self.context = double(title=u'Content title')
        self.configuration = NullTemplateConfiguration(self.context)
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = stubydoo.double()
        self.adapted = stubydoo.double()

        # This is normally registered during application startup.
        zope.component.provideHandler(zope.component.event.objectEventNotify)

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.INewsletterAttributes)
        def newsletter_attributes_adapter(context):
            return self.adapted
        zope.component.provideAdapter(newsletter_attributes_adapter)
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = stubydoo.double()
        self.adapted = stubydoo.double()

        # This is normally registered during application startup.
        zope.component.provideHandler(zope.component.event.objectEventNotify)

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.INewsletterAttributes)
        def newsletter_attributes_adapter(context):
            return self.adapted

        zope.component.provideAdapter(newsletter_attributes_adapter)
    def setUp(self):
        placelesssetup.setUp(self)

        self.document = stubydoo.double()
        self.document.body = u'<p>Test!</p>'
        self.config = stubydoo.double()

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.IHTMLBody)
        def body_attribute(doc):
            return stubydoo.double(__unicode__=lambda self:doc.body)

        zope.component.provideAdapter(body_attribute)

        self.compiler = CompilationStrategy(self.document, self.config)
Example #14
0
 def test_adaptation_to_html_image_cacheable_fails_if_cant_adapt_behavior(
         self):
     context = stubydoo.double()
     zope.interface.alsoProvides(context,
                                 interfaces.IPossibleHTMLImageCacheable)
     adapted = interfaces.IHTMLImageCacheable(context, None)
     self.assertTrue(adapted is None)
Example #15
0
    def test_returns_null_template_object_if_template_is_emptied(self):
        relation = double(to_object='template object')
        self.templating.template = relation
        self.templating.template = None

        template = self.templating.template_object
        self.assertTrue(isinstance(template, NullTemplate))
        self.assertTrue(template.context is self.context)
    def test_traversing_to_a_known_key_marks_request_for_publishing(self):
        value = object()
        request = double()
        self.cache_manager['the key'] = value

        self.cache_traverser.publishTraverse(request, 'the key')

        self.assertTrue(interfaces.ICacheRequest.providedBy(request))
    def test_traversing_to_a_known_key(self):
        value = object()
        request = double()
        self.cache_manager['the key'] = value

        traversed = self.cache_traverser.publishTraverse(request, 'the key')

        self.assertTrue(traversed is value)
 def setUp(self):
     super(TestNewsletterInterpolations, self).setUp()
     self.subscriber = stubydoo.double(
         name=u'',
         preferences_url=u'',
         removal_url=u'',
         format=u'',
     )
 def setUp(self):
     super(TestNewsletterInterpolations, self).setUp()
     self.subscriber = stubydoo.double(
         name=u'',
         preferences_url=u'',
         removal_url=u'',
         format=u'',
     )
Example #20
0
    def setUp(self):
        placelesssetup.setUp(self)
        self.context = zope.container.folder.Folder()
        self.request = stubydoo.double(form={})
        self.add_form = AddForm(self.context)

        self.adder = subscriber_list.SubscriberAdder(self.context,
                                                     self.request,
                                                     self.add_form)

        dates_locale = stubydoo.double()
        self.request.locale = stubydoo.double(dates=dates_locale)

        self.parsed_datetime = datetime.datetime.now()
        self.date_short_fmt = stubydoo.double(
            parse=lambda f, x: self.parsed_datetime
        )

        stubydoo.stub(dates_locale, 'getFormatter').\
                with_args('date', 'short').and_return(self.date_short_fmt)
        stubydoo.stub(dates_locale, 'getFormatter').\
                with_args('date', 'medium').\
                and_return(stubydoo.double(parse='ignored'))
        stubydoo.stub(dates_locale, 'getFormatter').\
                with_args('dateTime', 'short').\
                and_return(stubydoo.double(parse='ignored'))
        stubydoo.stub(dates_locale, 'getFormatter').\
                with_args('dateTime', 'medium').\
                and_return(stubydoo.double(parse='ignored'))

        zope.component.provideAdapter(Publication)
 def setUp(self):
     super(TestStyledPageCompilationStrategyWithNullConfiguration,
           self).setUp()
     self.config = double(
         xpath=NullTemplateConfiguration.xpath,
         css=NullTemplateConfiguration.css,
         html=u'<html><body></body></html>'
     )
     self.compiler = StyledPageCompilationStrategy(self.document, self.config)
Example #22
0
    def setUp(self):
        placelesssetup.setUp(self)
        self.portal = self.make_portal()
        setSite(self.portal)
        self.provide_mailhost(self.make_mailhost('MailHost'))

        self.portal['folder'] = stubydoo.double()

        self.mailing = mailing.Mailing()
Example #23
0
    def test_add_adds_subscriber_with_form_data(self):
        obj = stubydoo.double()
        obj.id = 'the subscriber id'

        stubydoo.stub(self.add_form.extractData).\
                and_return(('the data', None))
        stubydoo.expect(self.add_form.createAndAdd).\
                with_args('the data').and_return(obj)

        self.adder.add('email', 'format', None, None)
Example #24
0
    def configure_newsletter_from_content_behavior(self):
        self.behavior = stubydoo.double(subscribers=self.subscribers)

        @zope.component.adapter(None)
        @zope.interface.implementer(behaviors.INewsletterFromContent)
        def behavior_adapter(context):
            return self.behavior
        zope.component.provideAdapter(behavior_adapter)

        # This is normally registered during application startup.
        zope.component.provideHandler(zope.component.event.objectEventNotify)
 def setUp(self):
     placelesssetup.setUp(self)
     self.cache = {}
     self.context_keys = double(link=lambda *a:None,
                                unlink=lambda *a:None,
                                unlinkContext=lambda *a:None,
                                __contains__=lambda *a:True)
     zope.component.provideUtility(self.cache, interfaces.ICache)
     zope.component.provideUtility(self.context_keys,
                                   interfaces.IContextKeys)
     self.cache_manager = caching.CacheManager()
Example #26
0
    def test_compiles_template_with_context(self):
        compilation = double()
        stubydoo.stub(compilation, '__unicode__').and_return(u'Result')

        @zope.component.adapter(None)
        @zope.interface.implementer(interfaces.ICompilation)
        def compilation_adapter(context):
            return compilation

        zope.component.provideAdapter(compilation_adapter)

        self.assertEquals(self.view.render(), u'Result')
    def test_notify_modification(self):
        @zope.component.adapter(None, IObjectModifiedEvent)
        def handler(object, event):
            self.object = object
            self.event = event
        zope.component.provideHandler(handler)

        newsletter.setLastSent(self.context, stubydoo.double())
        self.assertTrue(self.object is self.context)
        self.assertEquals(self.event.descriptions[0].attributes,
                          ('last_sent',))
        self.assertTrue(self.event.descriptions[0].interface is
                        interfaces.INewsletterAttributes)
    def setUp(self):
        placelesssetup.setUp(self)
        zope.component.provideUtility(intids)

        portal = stubydoo.double(
            email_from_address="the site's email address",
            email_from_name="the site's name"
        )

        self.context = stubydoo.double()
        self.context.portal_url = stubydoo.double(
            getPortalObject=lambda x: portal
        )

        zope.interface.alsoProvides(portal,
                                    plone.app.controlpanel.mail.IMailSchema)

        self.behavior = stubydoo.double()

        @zope.component.adapter(None)
        @zope.interface.implementer(behaviors.INewsletterFromContent)
        def newsletter_from_content(context):
            return self.behavior
        zope.component.provideAdapter(newsletter_from_content)

        @zope.component.adapter(None)
        @zope.interface.implementer(zope.annotation.interfaces.IAnnotations)
        def annotations_adapter(context):
            annotations = getattr(context, '_annotations', None)
            if annotations is None:
                context._annotations = dict()
            return context._annotations
        zope.component.provideAdapter(annotations_adapter)

        self.adapted = behaviors.NewsletterAttributes(self.context)

        self.original_getToolByName_code = getToolByName.func_code
        getToolByName_stup = lambda context, name: getattr(context, name)
        getToolByName.func_code = getToolByName_stup.func_code
Example #29
0
    def test_add_should_set_subscriber_deactivation_date(self):
        # Don't break if the subscriber is to be wrapped.
        obj = stubydoo.double(__of__=lambda self, container: self)
        obj.id = 'the subscriber id'

        stubydoo.stub(self.add_form.extractData).\
                and_return(('the data', None))
        stubydoo.stub(self.add_form.createAndAdd).\
                with_args('the data').and_return(obj)

        self.adder.add('email', 'format', None, 'deactivation')

        self.assertEquals(subscriber.getSubscriberDeactivation(obj),
                          self.parsed_datetime)
    def test_notify_modification(self):
        @zope.component.adapter(None, IObjectModifiedEvent)
        def handler(object, event):
            self.object = object
            self.event = event

        zope.component.provideHandler(handler)

        newsletter.setLastSent(self.context, stubydoo.double())
        self.assertTrue(self.object is self.context)
        self.assertEquals(self.event.descriptions[0].attributes,
                          ('last_sent', ))
        self.assertTrue(self.event.descriptions[0].interface is
                        interfaces.INewsletterAttributes)
Example #31
0
    def test_send_should_be_able_to_not_fire_event(self):
        testpoint = stubydoo.double(event_called=lambda x: None)

        @zope.component.adapter(None, interfaces.INewsletterSentEvent)
        def handler(object, event):
            testpoint.event_called()
        zope.component.provideHandler(handler)

        stubydoo.expect(testpoint.event_called).to_not_be_called

        self.mailing.send(self.context,
                          suppress_events=True,
                          mailhost=self.mailhost,
                          subscribers=self.subscribers)
Example #32
0
    def setUp(self):
        placelesssetup.setUp(self)
        self.compilation_strategy = double()

        @zope.component.adapter(None, INullTemplateConfiguration)
        @zope.interface.implementer(interfaces.ICompilationStrategy)
        def compilation_strategy(content, config):
            self.compilation_strategy.context = content
            self.compilation_strategy.config = config
            return self.compilation_strategy

        zope.component.provideAdapter(compilation_strategy)
        stub(self.compilation_strategy, 'compile').\
            and_return('Compilation results')
Example #33
0
    def test_get_language_from_portal_if_content_has_no_language(self):
        self.metadata = None
        portal_state_view = double(default_language=lambda self: 'mayan')

        @zope.component.adapter(None, None)
        @zope.interface.implementer(
            zope.publisher.interfaces.browser.IBrowserView
        )
        def view(context, request):
            return portal_state_view
        zope.component.provideAdapter(view, name=u'plone_portal_state')

        tree = lxml.html.document_fromstring(self.configuration.html)
        lang = tree.xpath('/html/@lang')[0]
        self.assertEquals(lang, 'mayan')
Example #34
0
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = double()
        self.templating_behavior = double()
        template_content = double()
        self.templating_behavior.template_object = template_content
        zope.interface.alsoProvides(template_content, IPossibleTemplate)

        @zope.component.adapter(None)
        @zope.interface.implementer(ITemplating)
        def templating_behavior(context):
            return self.templating_behavior
        zope.component.provideAdapter(templating_behavior)

        template = double()

        @zope.component.adapter(IPossibleTemplate)
        @zope.interface.implementer(interfaces.ITemplate)
        def template_adapter(context):
            return template
        zope.component.provideAdapter(template_adapter)

        stub(template, 'compile').with_args(self.context).and_return(u'result')
Example #35
0
    def setUp(self):
        placelesssetup.setUp(self)
        self.context = double()

        zope.interface.alsoProvides(self.context, IAttributeAnnotatable)

        @zope.component.adapter(IAttributeAnnotatable)
        @zope.interface.implementer(IAnnotations)
        def annotations_adapter(context):
            if hasattr(context, '_annotations'):
                return context._annotations
            context._annotations = {}
            return context._annotations
        zope.component.provideAdapter(annotations_adapter)

        self.templating = Templating(self.context)
    def setUp(self):
        placelesssetup.setUp(self)

        self.context = stubydoo.double()

        # The persistency of NewsletterFromContent attributes is done in an
        # annotation.
        self.annotations = {}

        @zope.component.adapter(None)
        @zope.interface.implementer(zope.annotation.interfaces.IAnnotations)
        def context_annotations(obj):
            return self.annotations
        zope.component.provideAdapter(context_annotations)

        self.adapted = behaviors.NewsletterFromContent(self.context)
            def new_test(self):
                self.provided_html = provided_html.strip()
                self.expected_html = expected_html.strip()

                context = double(original_html=self.provided_html,
                                 original_save_images_locally=True)

                zope.interface.alsoProvides(
                    context, interfaces.IPossibleHTMLImageCacheable
                )
                self.subject = html_image_cacher.HTMLImageCacher(context)

                if self.on_cache:
                    context.original_save_images_locally = True
                else:
                    context.original_save_images_locally = False

                self.subject.url_opener = url_opener
                self.subject.image_blob_factory = img_blob_factory

                return original_test(self)