Snapshotting state with DemoStorage

View: New views
5 Messages — Rating Filter:   Alert me  

Snapshotting state with DemoStorage

by Martin Aspeli :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

I'm trying to set up a test case with Selenium RC. For this I need to be
able to set up a layer that includes a base state Plone site with some
data. I then need to be able to execute a number of Selenium tests
(which will perform operations that do ZODB commits across multiple
requests), rolling back to the snapshot state after each one.

Is it possible to create a fast "snapshot" with DemoStorage e.g. in a
ZopeTestCase layer, and then have the tear-down after each test revert
to this state? Doing the full setup (creating a new Plone site,
populating it) between each test run is prohibitively expensive!

I also saw zc.demostorage2, but didn't quite understand how it's
different or if it would help here.

Cheers,
Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@...
http://mail.zope.org/mailman/listinfo/zodb-dev

Re: Snapshotting state with DemoStorage

by Jim Fulton :: Rate this Message:

| View Threaded | Show Only this Message

Look at zc.selenium, which does this.

Jim

On May 27, 2008, at 5:22 PM, Martin Aspeli wrote:

> Hi,
>
> I'm trying to set up a test case with Selenium RC. For this I need  
> to be able to set up a layer that includes a base state Plone site  
> with some data. I then need to be able to execute a number of  
> Selenium tests (which will perform operations that do ZODB commits  
> across multiple requests), rolling back to the snapshot state after  
> each one.
>
> Is it possible to create a fast "snapshot" with DemoStorage e.g. in  
> a ZopeTestCase layer, and then have the tear-down after each test  
> revert to this state? Doing the full setup (creating a new Plone  
> site, populating it) between each test run is prohibitively expensive!
>
> I also saw zc.demostorage2, but didn't quite understand how it's  
> different or if it would help here.
>
> Cheers,
> Martin
>
> --
> Author of `Professional Plone Development`, a book for developers who
> want to work with Plone. See http://martinaspeli.net/plone-book
>
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>
> ZODB-Dev mailing list  -  ZODB-Dev@...
> http://mail.zope.org/mailman/listinfo/zodb-dev

--
Jim Fulton
Zope Corporation


_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@...
http://mail.zope.org/mailman/listinfo/zodb-dev

Re: Snapshotting state with DemoStorage

by Martin Aspeli :: Rate this Message:

| View Threaded | Show Only this Message

Jim Fulton wrote:
> Look at zc.selenium, which does this.

Thanks!

I'm struggling a little bit with making the leap to Zope 2 and
ZopeTestCase, though. I think the approach zc.selenium takes is a bit
more complex than what I need, because it seems to be doing some of the
Selenium controlling itself. The way I've used Selenium in Java before
uses a simple client driver (which has a Python version) talking to the
Selenium RC, which deals with opening the browser etc.

In this case, we used a base class for JUnit tests that did a database
clean-down to a known good state before each test run. If I can do the
basic test setup in a standard layer and do the "reset database to the
layer's setup state" before each test, I think we'd be good. I don't
particularly need to do the reset from within a Selenium test (i.e. with
a browser URL) or run tests from an HTML table.

I think the main problem is that I'm not terribly familiar with how
DemoStorage works, or how the Zope server (in a test case) ends up
getting its database. I'm worried that I may be asking the "wrong"
questions here, but to my mind, the three questions would be:

  - how can I use DemoStorage to snapshot a known state and then return
to it at all

  - how can I ensure that this is the storage that the Zope server sees

  - how can I actually access a server that's running inside a
ZopeTestCase over a URL, i.e. ensure that it binds to a port and serves
requests for the duration of the test run

Thanks,
Martin

--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@...
http://mail.zope.org/mailman/listinfo/zodb-dev

Re: Snapshotting state with DemoStorage

by Stefan H. Holek :: Rate this Message:

| View Threaded | Show Only this Message

You can base DemoStorage on another storage. This could be simple with  
ZTC, haven't tried in a while. See ZopeLite.sandbox() and sandbox.py.  
You may be able to get away with minor mods to the base classes, e.g.  
overriding the _app() method of Sandboxed/Functional.

Stefan


On 27.05.2008, at 23:22, Martin Aspeli wrote:

> Is it possible to create a fast "snapshot" with DemoStorage e.g. in  
> a ZopeTestCase layer, and then have the tear-down after each test  
> revert to this state? Doing the full setup (creating a new Plone  
> site, populating it) between each test run is prohibitively expensive!

--
Stefan H. Holek
stefan@...




_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@...
http://mail.zope.org/mailman/listinfo/zodb-dev

Re: Re: Snapshotting state with DemoStorage

by Stefan H. Holek :: Rate this Message:

| View Threaded | Show Only this Message

On 28.05.2008, at 09:48, Martin Aspeli wrote:

> I think the main problem is that I'm not terribly familiar with how  
> DemoStorage works, or how the Zope server (in a test case) ends up  
> getting its database. I'm worried that I may be asking the "wrong"  
> questions here, but to my mind, the three questions would be:

The tests get their database from Testing.custom_zodb.py

> - how can I use DemoStorage to snapshot a known state and then  
> return to it at all

See ZopeLite.sandbox

> - how can I ensure that this is the storage that the Zope server sees

See sandbox.Sandboxed and the AppZapper class

> - how can I actually access a server that's running inside a  
> ZopeTestCase over a URL, i.e. ensure that it binds to a port and  
> serves requests for the duration of the test run

ZopeTestCase.utils.startZServer()

And then something like urllib.urlopen(self.portal.absolute_url())

--
Stefan H. Holek
stefan@...

_______________________________________________
For more information about ZODB, see the ZODB Wiki:
http://www.zope.org/Wikis/ZODB/

ZODB-Dev mailing list  -  ZODB-Dev@...
http://mail.zope.org/mailman/listinfo/zodb-dev