plonewars.com

September 19th, 2007

Unit, Integration and Functional Tests With Plone

Unit, Integration and Functional Tests With Plone

Originally from del.icio.us/tag/plone by dirceu


from Yoda http://plonewars.com/2007/09/19/unit-integration-and-functional-tests-with-plone/







September 19th, 2007

General product development and migration tips for Plone 3.0 — Plone CMS: Open Source Content Management

General product development and migration tips for Plone 3.0 — Plone CMS: Open Source Content Management

Originally from del.icio.us/tag/plone by jonthomas1986


from Yoda http://plonewars.com/2007/09/19/general-product-development-and-migration-tips-for-plone-30-%e2%80%94-plone-cms-open-source-content-management/







September 19th, 2007

Rocky Burt: Unit, Integration, and Functional Testing with Plone

Disclaimer
This is plone testing as thought through by the author which is, as everything, just an opinion.

Types of Tests

Unit tests
Testing done in as extremely minimal fashion as possible.
Having some monstrous setup done before hand is not acceptable. These
tests are done in a mind set by which the developer knows what the inner
code looks like so he can test that certain inner code flags/values have
been set after running the test.
Integration tests
Testing done very similar to unit tests (that is
they’re all code based and don’t actually go through the browser
interface) but require some integration to have been performed. In
the case of Plone this often means having a complete plone site
installed with all the trimmings. Basically these are unit tests on
steriods. 95% of plone add-on developers write their tests these ways
(the fastest way to see if a test is an integration test is to see if it
uses PloneTestCase or ZopeTestCase … if it does, it’s an integration test).
If a test requires a working portal instance, it’s an integration test.
Functional tests
Testing from as close to the real environment as possible, in most casee
this means using something like selenium or testbrowser (I tend to use
testbrowser). These tests never touch actual code api’s (other than to run
the mock web browser).

An Example

Let’s say we have browser.py. Anyone familiar with the newer Zope 3 style
way of coding applications is familar with the browser module. In this
case, as expected, browser.py is giving us view classes that ultimately
will get accessed via a web browser. Here’s how we would write different types
of tests for that browser module.

But before we get into the actual tests, We need to begin by defining
browser.py as follows:

from Products.Five.browser import BrowserView
from Products.CMFCore import utils as cmfutils
class SimpleView(BrowserView):
    """A simple view."""
    def nextval(self):
        portal = cmfutils.getToolByName(self.context, 'portal_url') 
                 .getPortalObject()
        current = getattr(portal, '_simpleview_count', 0)
        portal._simpleview_count = current + 1
        return portal._simpleview_count
    def __call__(self):
        return 'Retrieved %i' % self.nextval()

Also need configure.zcml:

<configure
  xmlns="http://namespaces.zope.org/zope"
  xmlns:browser="http://namespaces.zope.org/browser">
<browser:page
    name="simpleview"
    for="*"
    class=".browser.SimpleView"
    permission="zope.Public"
    />
</configure>
Unit test

In general no setup will be performed for this at all.
Here the developer would simply import the browser module
and instantiate the view classes using python code. And then with the view
instance, test each of the methods. In general
when any additional functionality is needed, it’s done in the form of
mock objects.

Here’s what the test harness looks like (in this example, expected to live as
tests/test_unit.py):

import unittest
from zope.testing import doctest
def test_suite():
    return unittest.TestSuite(doctest.DocFileSuite
                              ('unit-example.txt',
                               package='testingexample'))

Here’s the test (in doctest-style) as is expected to live in
unit-example.txt:

First some mock objects.
    >>> class Mock(object):
    ...     def __init__(self, **kwargs):
    ...         for k, v in kwargs.items(): setattr(self, k, v)
    >>> portal = Mock()
    >>> context = Mock(portal_url=Mock(getPortalObject=lambda: portal))
We don't bother with request since we know the innards of our code and
the fact that it doesn't use the request for anything.
    >>> from testingexample.browser import SimpleView
    >>> view = SimpleView(context, None)
    >>> view.nextval()
    1
    >>> portal._simpleview_count
    1
And adjusting the private var manually will work as expected.
    >>> portal._simpleview_count = 50
    >>> view.nextval()
    51
    >>> portal._simpleview_count
    51
And then testing the string output of ``__call__``.
    >>> view()
    'Retrieved 52'
    >>> portal._simpleview_count
    52
The only way to see this break is if someone corrupted the _simpleview_count
value (which we should have to account for anyhow).
    >>> portal._simpleview_count = 'foobar'
    >>> view.nextval()
    Traceback (most recent call last):
    TypeError: cannot concatenate 'str' and 'int' objects
Integration test

Use a setUp that sets up a simple plone site and
installs any plone add-ons we need. Use code like
view = somecontentobj.restrictedTraverse(’@@someview’)
to look up a view that is being created with browser.py and interact with
that view component on an api level.

Here’s what the test harness looks like (in this example, expected to live as
tests/test_integration.py):

import unittest
import testingexample
from Testing import ZopeTestCase
from Testing.ZopeTestCase.zopedoctest import ZopeDocFileSuite
from Products.PloneTestCase import PloneTestCase
from Products.PloneTestCase.layer import PloneSite
from Products.Five import zcml
PloneTestCase.setupPloneSite()
class MainTestCase(PloneTestCase.PloneTestCase):
    def afterSetUp(self):
        zcml.load_config('configure.zcml', testingexample)
        self.portal._simpleview_count = 0
def test_suite():
    suite = ZopeDocFileSuite('integration-example.txt',
                             package='testingexample',
                             test_class=MainTestCase)
    suite.layer = PloneSite
    return unittest.TestSuite((suite,))

And here’s the actual tests:

In these tests we expect that the portal object has already been setup
(ala ``PloneTestCase``) and is available as simply ``portal``.
    >>> portal
    <PloneSite at /plone>
Our first integration test just checks to make sure that we can actually
lookup the view by traversing.
    >>> view = portal.restrictedTraverse('@@simpleview')
    >>> view is not None
    True
Our view instance is already expected to have a working *context* and
*request* so we can continue as expected.
    >>> view.nextval()
    1
    >>> portal._simpleview_count
    1
And adjusting the private var manually will work as expected.
    >>> portal._simpleview_count = 50
    >>> view.nextval()
    51
    >>> portal._simpleview_count
    51
And then testing the string output of ``__call__``.
    >>> view()
    'Retrieved 52'
    >>> portal._simpleview_count
    52
The only way to see this break is if someone corrupted the _simpleview_count
value (which we should have to account for anyhow).
    >>> portal._simpleview_count = 'foobar'
    >>> view.nextval()
    Traceback (most recent call last):
    TypeError: cannot concatenate 'str' and 'int' objects
Functional test

Use a setUp that sets up a simple plone site and
installs any plone add-ons we need. Instantiate a test browser instance
(via zope.testbrowser) and mimick browser actions to “log into” the site
and access whatever views were produced by browser.py.

Here’s what the test harness looks like (in this example, expected to live as
tests/test_functional.py):

import unittest
import testingexample
from Testing import ZopeTestCase
from Testing.ZopeTestCase import FunctionalDocFileSuite
from Products.PloneTestCase import PloneTestCase
from Products.PloneTestCase.layer import PloneSite
from Products.Five import zcml
PloneTestCase.setupPloneSite()
class MainTestCase(PloneTestCase.PloneTestCase):
    def afterSetUp(self):
        zcml.load_config('configure.zcml', testingexample)
        self.portal._simpleview_count = 0
def test_suite():
    suite = FunctionalDocFileSuite('functional-example.txt',
                                   package='testingexample',
                                   test_class=MainTestCase)
    suite.layer = PloneSite
    return unittest.TestSuite((suite,))

And here’s the actual tests:

These tests are all about seeing and testing what the browser sees.  We
make no assumptions on the innards of the code -- pretending we have indeed
never seen the code itself.
First we need to setup a browser instance.
    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
Now we can start checking things out.  Really all we can test here now
is that the output to the browser has an integer that increments each time.
    >>> browser.open(portal.absolute_url()+'/@@simpleview')
    >>> browser.contents
    'Retrieved 1'
    >>> browser.open(portal.absolute_url()+'/@@simpleview')
    >>> browser.contents
    'Retrieved 2'

Seeing It In Use

All of the example code here can be found in the svn collective as an actual
python package. Read the included README.txt to figure out how to set
it up in your own zope instance. The package is available at:
http://svn.plone.org/svn/collective/examples/testingexample/tags/rocky-blog-post-20070919/

The tests are meant to be run with:

$ ./bin/zopectl test -s testingexample

But don’t forget that when developing code you can save yourself a ton of time
by maintaining 100% unit test coverage. Then you can run the unit tests as
often as you want (at a very rapid speed) and only run the integration and/or
functional tests at milestone intervals. To run them separately you would do:

$ ./bin/zopectl test -m testingexample.tests.test_unit
$ ./bin/zopectl test -m testingexample.tests.test_integration
$ ./bin/zopectl test -m testingexample.tests.test_functional

Conclusion

Testing is great. I’m not particularly advocating test driven development
(it works for some people, but other people it does not). But it’s important
to understand the differences between the different types of tests. The
author suggests maintaining 100% unit test coverage and some (client-derived)
acceptable amount of functional tests. Integration tests aren’t so important
when you already have good unit and functional test coverage.

Rocky Burt: Unit, Integration, and Functional Testing with Plone

Originally from Planet Plone


from Yoda http://plonewars.com/2007/09/19/rocky-burt-unit-integration-and-functional-testing-with-plone/







September 19th, 2007

Maurits van Rees: Plone en Single Sign On

Existentiële zaken

Wat is het? Eenmalig authenticeren voor meerdere applicaties. 1
metasessie. Je hebt ook Web SSO, specifiek voor webapplicaties.

Waarom zou je het willen? Gebruikers willen het graag, al draagt het
niets wezenlijks toe. Het is gewoon gemakkelijk. Wel heb je minder
accounts nodig, net zoals bij bijvoorbeeld OpenID. Ook ligt de focus
van het beveiligingsbeleid centraal, dus beleids- en beheersmatig is
het handig.

Hoe gaat het in zijn werk? Er is 1 bron die de authenticatie
regelt. Die bron wordt vertrouwd door andere applicaties. Een
betrouwbaar protocol is opgesteld voor deze relatie.

Plone en SSO

Je kan regelen dat meerdere Plone sites dezelfde gebruikersgegevens
hebben en inloggen bij de een je meteen authenticeert voor de
ander. Plone kan je als front-end gebruiken voor andere sites,
bijvoorbeeld middels atom of rss feeds. Je kan andere
(non)webapplicaties in dezelfde sessies hebben. Plone kan ook net als
anderen gebruik maken van LDAP, al hebben we het daar vanavond niet
over.

CAS is een SSO server gebouwd aan de Yale universiteit. Het is een
open protocol. Plone kan daarmee praten, middels PlonePAS en CAS4PAS
en optioneel PloneCASLogin.

Sessie A

Je bezoekt (maakt een http request naar) Plone site A. Je krijgt een
zogenoemde challenge (uitdaging) van CAS4PAS, die je redirect naar
de CAS server over https. Daar log je in. Die CAS server zet een
cookie en redirect je terug naar de callback service (dus Plone site
A) met een ticket. Plone Site A gaat met dat ticket zelf weer terug
naar de CAS server en vraagt of het ticket geldig is. Als het klopt,
verwijdert de CAS server de ticket, zegt tegen Plone site A dat het in
orde is en geeft het netID, de gebruikersnaam van de persoon die zich
zojuist heeft aangemeld. Plone site A geeft vervolgens een response
aan de gebruiker, met een Plone cookie.

Sessie B

Je bezoekt Plone Site B. Je kiest de inloglink naar de CAS server of
krijgt automatisch een redirect naar de authenticatie. De CAS server
herkent de sessie op basis van je cookie. CAS stuurt dus meteen een
ticket terug, zonder dat je je gebruikersnaam en wachtwoord in hoeft
te vullen. Daarna gaat het hetzelfde als bij sessie A.

Qua backend wordt vaak LDAP gebruikt of SQL.

Maurits van Rees: Plone en Single Sign On

Originally from Planet Plone


from Yoda http://plonewars.com/2007/09/19/maurits-van-rees-plone-en-single-sign-on/







September 19th, 2007

Ajouter un lecteur de mp3 à votre site Plone

Ajouter un lecteur de mp3 à votre site Plone Voici un lecteur simple à installer et à utiliser: … ://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en” i18n:domain=”plone”>


from Yoda http://plonewars.com/2007/09/19/ajouter-un-lecteur-de-mp3-a-votre-site-plone/







September 19th, 2007

Welcome on llakomy.com — Lukasz Lakomy’s website

Welcome on llakomy.com — Lukasz Lakomy’s website

Originally from del.icio.us/tag/plone by reynard71


from Yoda http://plonewars.com/2007/09/19/welcome-on-llakomycom-%e2%80%94-lukasz-lakomys-website/







September 19th, 2007

Plone - Wikipédia

Plone - Wikipédia

Originally from del.icio.us/tag/plone by bidouill21


from Yoda http://plonewars.com/2007/09/19/plone-wikipedia/







September 19th, 2007

Reinout van Rees: First plone user meeting in the Netherlands

I’ve made a Dutch summary of the first plone user meeting in the Netherlands.

Reinout van Rees: First plone user meeting in the Netherlands

Originally from Planet Plone


from Yoda http://plonewars.com/2007/09/19/reinout-van-rees-first-plone-user-meeting-in-the-netherlands/







September 19th, 2007

Sidnei da Silva: Strategic Blindness

On his Strategy Letter VI article, Joel writes about something that many people are starting to realize: that the current Web 2.0 is not much better than Smart (or even Dumb!) Terminal days, when you had to care about memory constraints and there were no standards for interop between applications, or even UI guidelines.

Then after a short history lesson, he speculates that people should stop worrying about the size of their JavaScript and that eventually JavaScript would be compiled to native code a new portable language will appear that can be compiled to JavaScript (did someone tell him about GWT at all?).

What’s going to happen? The winners are going to do what worked at Bell Labs in 1978: build a programming language, like C, that’s portable and efficient. It should compile down to “native” code (native code being JavaScript and DOMs) with different backends for different target platforms, where the compiler writers obsess about performance so you don’t have to. It’ll have all the same performance as native JavaScript with full access to the DOM in a consistent fashion, and it’ll compile down to IE native and Firefox native portably and automatically. And, yes, it’ll go into your CSS and muck around with it in some frightening but provably-correct way so you never have to think about CSS incompatibilities ever again. Ever. Oh joyous day that will be.

Well, after Paul Graham said that Microsoft is Dead, the only thing I can think of is that Joel has started to believe Paul’s lie, and stopped paying attention to what comes out of Microsoft.

Everyone that is paying attention to Silverlight and has not been blinded by the anti-Microsoft FUD, something that even the Linux Foundation executive director condemns, will realize where Microsoft is heading with the introduction of the DLR, specially if you make the connection between Joel’s post and Managed JScript. I really hope that people will soon take their tinfoil hats off and start paying more attention to what’s coming out of Microsoft, specially since there is an option in Mono, which is a completely open implementation of .NET, and now with Moonlight a JavaScript compiler  will be soon hitting your beloved Linux Desktop anytime now.

And listen, Joel. We don’t need no new stinking portable language that can compile to JavaScript. If we get to write code in our own lovely favorite language, be it Python or even Ruby, being able to access the dreaded DOM and to top it off compile it to native machine code, what could be better than that?

In other news, if you just consider the approach of making JavaScript faster instead of compiling it, you might want to keep an eye on Mozilla’s Tamarin Project. Mum’s the word that some exciting news will be coming out of that in the near future.

Sidnei da Silva: Strategic Blindness

Originally from Planet Plone


from Yoda http://plonewars.com/2007/09/19/sidnei-da-silva-strategic-blindness/







September 19th, 2007

Martin Aspeli: Real Soon Now - An update on my book

Professional Plone Development should ship end of September!

Martin Aspeli: Real Soon Now - An update on my book

Originally from Planet Plone


from Yoda http://plonewars.com/2007/09/19/martin-aspeli-real-soon-now-an-update-on-my-book/