Skip to content.

Etria Lists

 

[quills-dev] [Collective-checkins] r49758 - Quills/trunk/tests

quills-dev at lists.etria.com quills-dev at lists.etria.com
Thu Sep 20 13:38:20 UTC 2007


Author: tomster
Date: Thu Sep 20 13:38:20 2007
New Revision: 49758

Added:
   Quills/trunk/tests/browser.rst
Modified:
   Quills/trunk/tests/base.py
   Quills/trunk/tests/test_docfile.py
Log:
foundation for future browser tests.

 * based the QuillsTestcases on a common Mixin class
 * added a new QuillsSite layer for the browser tests
 * made the PloneSite layer for the other testcases explicit
 * added stub for the new browser tests 

currently we only visit a document rather than a quills instance in that browser test, because the latter raises an exception atm, this will be changed in a future revision, but i wanted to commit this intermediate step.

Modified: Quills/trunk/tests/base.py
==============================================================================
--- Quills/trunk/tests/base.py	(original)
+++ Quills/trunk/tests/base.py	Thu Sep 20 13:38:20 2007
@@ -5,35 +5,99 @@
 """
 
 from Testing import ZopeTestCase
+from Products.Five.testbrowser import Browser as BaseBrowser
+from transaction import commit
+from AccessControl.SecurityManagement import newSecurityManager
+
+from Products.Five import zcml
+
+# CMFCore imports
+from Products.CMFCore.utils import getToolByName
 
 # Let Zope know about Quills
 ZopeTestCase.installProduct('Quills')
 
 # Import PloneTestCase - this registers more products with Zope as a side effect
-from Products.PloneTestCase.PloneTestCase import PloneTestCase
+from Products.PloneTestCase import PloneTestCase
 from Products.PloneTestCase.PloneTestCase import setupPloneSite
+from Products.PloneTestCase.layer import PloneSite
+
+import quills.core
+import quills.app
 
 # Set up a Plone site, and apply the Quills extension profile
 setupPloneSite(products=['Quills'])
 
+class QuillsSite(PloneSite):
 
-class QuillsTestCase(PloneTestCase):
-    """Base class for integration tests for the 'Quills' product. This may
-    provide specific set-up and tear-down operations, or provide convenience
-    methods.
-    """
+    @classmethod
+    def setUp(cls):
+        app = ZopeTestCase.app()
+        portal = app.plone
+        # login as admin (copied from `loginAsPortalOwner`)
+        uf = app.acl_users
+        user = uf.getUserById(PloneTestCase.portal_owner).__of__(uf)
+        newSecurityManager(None, user)
+        zcml.load_config('configure.zcml', quills.core)
+        zcml.load_config('configure.zcml', quills.app)
+        setup_tool = getToolByName(portal, 'portal_setup')
+        setup_tool.runAllImportStepsFromProfile('quills.core')        
+        setup_tool.runAllImportStepsFromProfile('quills.app')        
+
+        commit()
+        ZopeTestCase.close(app)
 
 
-class QuillsDocTestCase(PloneTestCase):
+
+class Browser(BaseBrowser):
+
+    def addAuthorizationHeader(self, user=PloneTestCase.default_user, password=PloneTestCase.default_password):
+        """ add an authorization header using the given or default credentials """
+        self.addHeader('Authorization', 'Basic %s:%s' % (user, password))
+        return self
+
+class QuillsTestCaseMixin:
     """Base class for integration tests for the 'Quills' product. This may
     provide specific set-up and tear-down operations, or provide convenience
     methods.
     """
+    def getBrowser(self, logged_in=False):
+        """ instantiate and return a testbrowser for convenience """
+        browser = Browser()
+        if logged_in:
+            browser.addAuthorizationHeader()
+        return browser
 
     def afterSetUp(self):
         self.loginAsPortalOwner()
         self.portal.invokeFactory('Weblog', id='weblog')
+        self.portal.invokeFactory('Document', id='doc')
         self.weblog = self.portal.weblog
+        self.portal.portal_workflow.doActionFor(self.portal.doc, "publish")
+
+
+class QuillsTestCase(QuillsTestCaseMixin, PloneTestCase.PloneTestCase):
+    """Base class for integration tests for the 'Quills' product. This may
+    provide specific set-up and tear-down operations, or provide convenience
+    methods.
+    """
+
+    layer = PloneSite
+
+
+class QuillsFunctionalTestCase(QuillsTestCaseMixin, PloneTestCase.FunctionalTestCase):
+    """ a class for running functional tests."""
+
+    layer = QuillsSite
+
+
+class QuillsDocTestCase(QuillsTestCaseMixin, PloneTestCase.PloneTestCase):
+    """Base class for integration tests for the 'Quills' product. This may
+    provide specific set-up and tear-down operations, or provide convenience
+    methods.
+    """
+
+    layer = PloneSite
 
 
 class QuillsContributorDocTestCase(QuillsDocTestCase):

Added: Quills/trunk/tests/browser.rst
==============================================================================
--- (empty file)
+++ Quills/trunk/tests/browser.rst	Thu Sep 20 13:38:20 2007
@@ -0,0 +1,9 @@
+Quills browser tests
+====================
+
+Here we klick ourselves through a Quills instance and check that everything is in order. First some boilerplate to get our browser up and running:
+
+    >>> self.loginAsPortalOwner()
+    >>> browser = self.getBrowser(logged_in=True)
+    >>> browser.handleErrors = False
+    >>> browser.open('http://nohost/plone/doc/')

Modified: Quills/trunk/tests/test_docfile.py
==============================================================================
--- Quills/trunk/tests/test_docfile.py	(original)
+++ Quills/trunk/tests/test_docfile.py	Thu Sep 20 13:38:20 2007
@@ -7,7 +7,9 @@
 from Products.PloneTestCase.layer import PloneSite
 
 from Products.Quills.config import PROJECTNAME
-from base import QuillsDocTestCase, QuillsContributorDocTestCase
+from base import QuillsDocTestCase
+from base import QuillsContributorDocTestCase
+from base import QuillsFunctionalTestCase
 
 
 ZOPE_DEPS = []
@@ -30,6 +32,14 @@
     )
 
     suite.addTest(ZopeDocFileSuite(
+        'browser.rst',
+        package='Products.Quills.tests',
+        test_class=QuillsFunctionalTestCase,
+        optionflags=doctest.ELLIPSIS,
+        )
+    )
+
+    suite.addTest(ZopeDocFileSuite(
         'tests.txt',
         package='quills.core.tests',
         test_class=QuillsContributorDocTestCase,

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Collective-checkins mailing list
Collective-checkins at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/collective-checkins



More information about the quills-dev mailing list