Re: [Zope-CMF] [dev] writing tests for CMF 2.1

2006-11-09 Thread Chris Withers

Hi All,

yuppie wrote:

Layers
--

ZCML is set up using test layers. Their setUp() and tearDown() methods 
are only run once for all tests in the layer.


Maybe of interest, I've attached the layers file I use when testing Zope 
2 apps. It does the right thing w.r.t. having a DemoStorage for each 
layer, letting you safely commit transactions containing layer setup and 
then using the using transaction.begin()/transaction.abort() dance in 
the tests themselves.


Is this code useful? Should I look to check it in to the core anywhere?

For functional tests that depend on a complete CMF site, you can use the 
FunctionalLayers defined in the testing modules. They have to be used 
with ZopeTestCase's FunctionalTestCase 


Hmmm, which version of Zope did this arrive in?

Finally, a question of my own, how do you use layers with doctests?

cheers,

Chris

--
Simplistix - Content Management, Zope  Python Consulting
   - http://www.simplistix.co.uk
import Globals
import logging
import transaction
import Zope2

from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
# this import, rather evilly, causes Zope2.bobo_application and Zope2.DB
# to come into existence :-(
from Testing.ZopeTestCase import ZopeLite
from Testing.ZopeTestCase.utils import makerequest
from ZODB import DB
from ZODB.DemoStorage import DemoStorage


state = [Zope2.DB]

def setChickens(db):
# Zope 2 chickens
Globals.BobobaseName = db.getName()
Globals.DB = db
Zope2.DB = db
Globals.UndoManager=db
ZopeLite.DB = db
junk_db, name, version_support = Zope2.bobo_application._stuff
Zope2.bobo_application._stuff = db, name, version_support

def addDB():
global state
previous = state[-1]
storage = DemoStorage(base=previous._storage)
db = DB(storage)
# cluck
db.classFactory = previous.classFactory
# cluck cluck
setChickens(db)
state.append(db)


def removeDB():
global state
db = state.pop()
db.close()
# un-cluck
setChickens(state[-1])

class Layer1:

@classmethod
def setUp(cls):
addDB()
# etc
# commit changes
transaction.commit()

@classmethod
def tearDown(cls):
# etc
noSecurityManager()
removeDB()



___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


[Zope-CMF] [dev] writing tests for CMF 2.1

2006-11-07 Thread yuppie

Hi!


Since CMF 2.0 I did a lot of test refactoring, changing the ways CMF 
tests are set up. Goal was to use more generic and up to date testing 
patterns, making it easier to write new tests.


Here is an overview what changed:


ZopeTestCase.app()
--

All tests that depend on a running Zope application use now 
ZopeTestCase's ZopeLite app. It is not compatible with Zope2.app(), so 
don't use Zope2.app() anymore. ZopeLite doesn't start up Products by 
default, you have to specify required Products explicitly using 
ZopeTestCase.installProduct(). Not each Product has to be initialized 
that way. Don't initialize Five that way - ZCML is set up differently.



Layers
--

ZCML is set up using test layers. Their setUp() and tearDown() methods 
are only run once for all tests in the layer.



Functional Tests


For functional tests that depend on a complete CMF site, you can use the 
FunctionalLayers defined in the testing modules. They have to be used 
with ZopeTestCase's FunctionalTestCase or FunctionalDocFileSuite test 
cases. This makes sure each test gets its own DemoStorage sandbox. You 
can commit changes to the site and don't have to care about the teardown.


It is now easy to set up zope.testbrowser based tests. See 
CMFCalendar.browser.tests for an example.


See also http://plone.org/documentation/tutorial/testing/functional-tests


Using Testrecorder
--

You can use zope.testrecorder for creating the testbrowser tests. To 
make sure you have the same setup as the tests and to enforce test 
translations, you can replace your etc/site.zcml by this::


configure xmlns=http://namespaces.zope.org/zope;
  include
  package=Products.CMFCore
  file=testing.zcml
  /
  include package=Products.CMFDefault/
  include package=Products.CMFTopic/
  include package=Products.DCWorkflow/
  include package=Products.CMFCalendar/
/configure

Set up a site called 'site' and start recording.

See also http://plone.org/documentation/tutorial/testing/zope-testrecorder


Any questions or comments are welcome.

Cheers,

Yuppie

___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests


Re: [Zope-CMF] [dev] writing tests for CMF 2.1

2006-11-07 Thread Jens Vagelpohl

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


On 7 Nov 2006, at 18:00, yuppie wrote:


Hi!


Since CMF 2.0 I did a lot of test refactoring, changing the ways  
CMF tests are set up. Goal was to use more generic and up to date  
testing patterns, making it easier to write new tests.


Thanks a lot for that work. It's good to see that you instituted a  
good and consistent pattern to follow when it comes to creating a  
test fixture for individual test classes.


jens



-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.1 (Darwin)

iD8DBQFFUVEfRAx5nvEhZLIRAjVJAJ45I53mJi4cguLjHMfhbSMpjEclKgCghyvg
lCNBDC1yzXyFBWpzwstf+jg=
=Fec0
-END PGP SIGNATURE-
___
Zope-CMF maillist  -  Zope-CMF@lists.zope.org
http://mail.zope.org/mailman/listinfo/zope-cmf

See http://collector.zope.org/CMF for bug reports and feature requests