Weblog
Jordan Baker: Plone Testing Tools and Techniques
Tutorial by Jordan Baker, Scryent, Canada
Geared towards developers this presentation walks you through developing a simple Plone 3 product using a test-driven or test-first approach. Techniques covered include unit testing, PloneTestCase, test layers, mocking and more. This is an updated and expanded version of the talk "Hone Your TestFu" given at the Plone Symposium East 2009.
I am using Plone since version 1.0. Senior consultant and founder of Scryent, in Toronto, Canada.
Slides are at http://tinyurl.com/pttt-slides
You don't always have to test. Sometimes you are just doing a prototype. But in my opinion: if you write production code, you should write tests. It improves code quality; reduces defects; makes your code more maintainable; it nudges you into more modular, loosely coupled code as that is easier to test; it keeps you focused: if the tests pass then you are done; when you have good test coverage, you can refactor with confidence.
Test first: write the test first, then start coding. It forces you to think about requirements up front. And manual testing is slow and error-prone.
Test levels: functional/system (black box), integration (your code in combination with Plone), unit (just your code).
More tests is not always better. Those tests need to be maintained too. With too many tests, it may start taking too long to run all the tests. Focus on lots of lower level tests as they are fast to run.
Unit tests: written from the developer's perspective. Test your components in isolation; use mocking techniques when you need to test integration with other components.
When working on a particular problem, try running only the immediately relevant tests. Try bin/instance test --help for some options you can pass. When those tests pass, run all tests again to check for unexpected failures.
Integration tests: test the integration of your code with Plone. Can you create the content types you made in the actual Plone Site? Do the correct values end up in the portal_catalog? Are the extra roles you defined actually added when you install your product?
Recently I started using collective.testcaselayer to simplify test setup. It simplifies repetitive Plone testing boiler plate.
Add it in your setup.py in extras_require and tests_require. Then in the eggs of your buildout add your.package[tests].
Use roadrunner to speed up testing: it sets up the layers (the Plone Site) and keeps that available so the setup is much much faster the next time you run those tests. There are some problems with for example z3c.autoinclude. I want to sprint on roadrunner this weekend.
Doctests look like interactive python sessions with documentation/explanation added.
Functional and system tests: end-to-end tests, black box tests, often zope.testbrowser tests, or with Twill or Selenium. Perhaps smoke tests: add specific tests for the most important paths that are used in your Plone Site. Twill is a domain specific language for performing web tests. It also provides a python API.
Use mocking to e.g. patch the time.time method, or urllib, or the MailHost. Martin Aspeli created plone.mocktestcase.
Coverage: answers the question: are all code paths executed in the tests. Does not guarantee that there are no bugs in the code. Use z3c.coverage to get html reports of the coverage.
Write tests at the lowest lelel possible. Take your time, write out what you are trying to do in English first. Is it too hard to test, then simplify your code, split it out.
I want to have an open space on testing.
Rok Garbas: Complex Forms with z3c.form
By Rok Garbas, Slovenia
Rok Garbas talks about the z3c.form form framework. Everybody is talking about is, using it, so it is time you learn how to (ab)use it and step into the Plone future. Tricks and things you might want to hear again. I won't speak about the internal structure, or why you would want to use it, or compare it with other frameworks.
For code examples, see his talk once it is uploaded to the Plone Conference 2009 website.
On the form you can set ignoreContext and ignoreRequest to control whether the form displays any values and where it gets it from.
Don't forget to package="plone.app.z3c.form" /> in your zcml when you use z3c.form in Plone.
You can register zope vocabularies and use that in your forms.
You can change the form layout. For that you create a layout factory, inheriting from plone.z3cform.templates.ZopeTwoFormTemplateFactory.
You can define your own widgets, for example to combine three inputs into one field.
You can create a custom data converter. It converts from the field to the widget (e.g. split fullname field into first name and last name inputs in the widget) or the other way around.
Within the form normally the default widgets are used. If you want to use your own widgets, you need to override the widgetFactory for that field in the form definition.
You can create group forms, which can be compared to Archetypes forms with tabs. Inherit from z3c.form.group.GroupForm.
In form wizards you can combine steps, so you can link different forms. Use collective.z3cform.wizard.
For more information, see http://docs.zope.org/z3c.form and http://pypi.python.org/pypi/plone.app.z3cform
Read Rok Garbas blog.
Alexander Limi: The future of Plone
Plone conference 2009 keynote by Alexander Limi
Alan Runyan is not here because he just had a baby (applause). The first South American Plone conference will be held this year.
Plone Foundation has been kicking ass this year; Jon Stahl did good work there (and is also having a baby). A lot of money was raised and spent to help more core people go to other conferences, also bigger industry events to represent Plone. Also some packages have been relicensed to make it easier to use them in other projects. Hosting of http://plone.org is now done by Six Feet Up. We are putting money into paying people to go to sprints. Dogin more marketing and evangelism.
Plone 4 is estimated to be released at the end of 2009. Release manager is Eric Steele. An amazing 26 new features (plips). We hope to have an alpha release at the end of the conference. It is the "Snow Leopard" of Plone releases, fixing lots of stuff in the background. Speedup, blob file storage, better memory management (partly because of using python 2.6), scales better.
Plone 5. Expected mid 2010 (well, maybe). I see Hanno Schlichting smiling, the release manager. Focus areas:
- Approachability. New content framework: Dexterity; but Archetypes is not going away. Dexterity is thorugh the web schema editing, with round trip support. Theming has become too hard; Deliverence: theming done right. We will use xdv for this. There will be talks about Deliverance this conference. We use this on the http://plone.org website already, so we believe in this.
- Plone needs to be faster. Partly we do this by using less code, Plone trunk plus all dependencies was at some point about 800,000 lines, instead of the 1 million lines of Plone 3.2. Using Chameleon for templating will make Plone faster. You can already use that on Plone 3.3 today. So more speed coming to you soon. We are going to run performance tests to see if Plone is not suddenly getting slower without us noticing.
- Simplicity. New layout system called Deco. It is a new approach to page editing. You will have page layouts composed of tiles, small boxes of text, images, lists, forms, polls, anything. "Tiles are the new apps." Where you would currently create a new content type you could probably create a new tile instead.
Deco: full page editing interface. What you edit is what you get. Separates layout from format. There will be no need for grid management, so not something like "add a row", "add a column". (Alex now does a Deco demo. Hey, Plone has a pony!)
Opportunities. Plone 4 and 5 are solving some basic problems. I want us to change the world again. Community: we want new talent, new web sites, new add-ons; it should be easier to get more people involved in Plone. We are not doing enough shouting from the roof tops. We know some of the weaknesses of Plone so we keep quiet; but all other system have their weaknesses as well. Be proud of Plone! What is our identity? Collaboration? Publishing? Simple apps? Using something like Amazon EC2 will help us as it makes it easier to run a Plone site. It should be simple to create small applications with Plone; Dexterity should help there. Going after Drupal, Wordpress we will lose, as they will always be cheaper. We are more up against frameworks like Alfresco and Documentum.
The Plone software needs to be more performant, self-documenting (sphinx, amberjack), more quality assurance (I will be running my blog on Plone 4 and when that is stable enough I will switch to Plone 5; the site might be down sometimes, but that is okay, it makes Plone better).
Be great. Talk more about Plone. Improve http://plone.org. It used to be a great driver of innovation.
Widen participation. Please start a Plone user group in your area. Evangelize Plone. It's all about you. Thank you for making Plone better!
Don't just complain. Complain and then try to make it better.
Plone Conference 2009 Intro
Short intro about the plone conference 2009.
The Plone Conference 2009 has just started. I am there with my Zest Software colleagues Jean-Paul and Fred. Location is Budapest, capital city of Hungary. It is the biggest Plone conference so far, with about 400 attendees.
Thomas Moroz talked a bit about KARL. He works for the Open Society Institute (OSI) that helped organize the conference. KARL is one of the largest sites built with Plone; a knowledge management system. He will talk about it in more dpeth later this week.
Python User group Netherlands meeting
The three-monthly meeting of the Dutch python user group was held Thursday 24 September 2009 in Amsterdam, in the Beurs van Berlage, organised by Go2People. First a half-hour presentation about Phatch, then some lightning talks, another half-hour presentation on MonetDB and moving from python 2 to python 3, then a few more lightning talks.
My brother Reinout was also there and of course he wrote a summary too.
Stani: Phatch - Batch photo processing for everyone
Lots of photo data, including metadata. You have ImageMagick. Phatch allows you to resize images, do colour profiling. Combine actions. Prefabricated recipes. You don't need to know how to do graphics manipulation. You can remove metadata so you can upload photos anonymously to sites. You can have a droplet on your desktop; just drop an image on it and it will do the actions you specified. Safe and unsafe mode. Safe restricts you; in unsafe mode you have the full power of python. It's a command line tool, but also a UI. Uses open source fonts. Phatch can do anything Gimp and ImageMagick does and more as they are the back ends, including PIL and blender. Its goal is to unite all open source graphics tools. Anyone can submit new objects. Works on Linux and mostly on Windows and Mac, but we need more developers there. About six developers now. Someone has plans to work on Django integration. Link: http://photobatch.stani.be/
Jasper Spaans, Fox-IT: Pycuda - massively parallel computing
Calculating with the GPU (Graphical Processing Units). GPU's are incredibly fast for parallel computations compared to their price. Cuda is only nor Nvidia. OpenCL does that too, and that can also use ATI/AMD. Use it for parallel algorithms. PyCuda is a python interface for cuda. Slides in Dutch: http://jasper.es/talks/pun2009-09
Wim Feijen, Go2People: Bazaar (and mercurial and git)
Bazaar: you can have one or more repositories. You can work and commit locally. It's simple. It tracks movements. You can branch projects. Look at http://github.com (not only for git users) and http://bitbucket.org, for free project hosting.
Remco Wendt, Maykin Media: libraries that you love
Does anyone know of a library that is cool to use? Speak up about it!
- Simon: greenlets; does micro threads; nice for animation, xml parser, http://pypi.python.org/pypi/greenlet
- zc.buildout: separate different project environments, repeatable deployment, http://pypi.python.org/pypi/zc.buildout
- pysvn: bindings for svn in python, http://pysvn.tigris.org/
- Ivo: virtualenv, keep libraries separate, sandbox them, http://pypi.python.org/pypi/virtualenv
- Tim: Paste: WSGI library (and other stuff), http://pypi.python.org/pypi/Paste
- werkzeug: like paste but different - http://pypi.python.org/pypi/Werkzeug
- WebOb, request and response objects: http://pythonpaste.org/webob/
- repoze.who, repoze.what: WSGI authentication and authentication framework, middleware, http://docs.repoze.org/who/ and http://what.repoze.org/docs/1.x/
- Fabric: remote deployment tool, http://docs.fabfile.org/0.9/
- grok: web framework, zope 3, without zcml headaches, http://grok.zope.org/
- scrapy: build web scrapers, http://scrapy.org/
- lamson: smtp server framework in python, http://lamsonproject.org/
- pep8, python style guide checker, finally easy_installable, http://pypi.python.org/pypi/pep8
Jan Jaap Driessen (Health Agency) and Sylvain Viollon (Infrae): Grok
Web framework, based on Zope. Even cavemen can use Zope. Just had a sprint about Grok. Takes the pain out of working with Zope. Zope has lots of layers, configuration, zcml, adapters, whatever. With Grok you do not register your stuff in zcml. Set of default settings. Grok "groks" your code, understands your code without needing a separate configuration language. Grok 1.0 is due for release this or next week. We have been using it for three years already. http://grok.zope.org
Gijs Molenaar, UvA, CWI: MonetDB and python 3
DBMS, developed by CWI, open source, BSD, platform for scientific research, not only SQL, http://www.monetdb.nl. Good for big databases; SkyServer is 6TB. For query intensive apps that are mostly read-only. For complex data models beyond SQL. Sometimes outperforms other databases by a hundred times for big tables.
It is a column based storage database. All columns are shown separately. Flexible kernel, which is easily extensible. SQL front end, but not limited to SQL; can use Xquery.
You can store xml documents in your database. Monet takes the document apart and stores it in several tables.
There are APIs for Ruby, PHP, python, perl (needs a rewrite but nobody wants to touch it), C, java. The CWI at the University of Amsterdam wanted me to rewrite the python API. MonetDB API is the wire protocol. Basic functions: set up connection, execute commands, parse the response, chop queries and responses in blocks. python.sql is the implementation of all DBAPI 2.0 functionality. Bridge between this and MonetAPI (mapi).
There were tests available for the MySQL python API, so I borrowed those for Monet. We looked at supporting python 2 and 3. We did not want to use two trees. We decided to do a 2+3 hybrid, though Guido van Rossum tells us not to do that. In python 3 there is a new IO layer with bytes and strings. New IO layer is used in the mapi layer. We made two versions here, mapi2.py and mapi3.py as it was too hard to combine, with exceptions that were no longer there in python 3. We do a python 3 version check in only two places, like conditionally importing mapi2 or mapi3, so not too bad. Tip: don't use print, use logging.
The hybrid python2-3 model works quite well in our case as the API is quite small. We minimised code duplication. Not advised for all projects.
Future work: bug fixes, port the xquery api, currently I am rewriting the C api (mapilite), unit tests in python using ctypes, having problem with structs.
Something completely different. http://pythonic.nl non-profit amateur web hosting provider for python web development. Focus on django.
Question: How mature is MonetDB? Well, there have been cases of data loss, but it has gotten better the last few years and it has been used in various projects.
Tim Molendijk: debugging
I usually just hunt for a bug, kill it and forget how I did the debugging and not improve it next time. But I am learning. I should probably use the python debugger, but usually I start with adding a few print statements. But with WSGI applications that normally does not work. So yes, next step is (i)pdb. For Django: Django debug toolbar.
Suggestions from the crowd: post mortem debugger, Twill, zc.testbrowser, mechanize, Selenium, winpdb, pydev for eclipse (you can still use vim for writing the code if you have to), werkzeug (for django).
Maurits van Rees: international emails
Short version of a presentation I gave at my employer Zest Software and that I blogged about recently. Suggestion from Jasper Spaans: use lamson (mentioned above), an smtp server framework in python.