[Zope] Unit testing (no html...)

Robert Rottermann robert@redcor.ch
Mon, 27 May 2002 17:57:05 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_009F_01C205A7.E96F7BB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 8bit

In the Zope developer book  which you find on Zop.org under documentation is
a chapter on unittesting.
To give you a headstart I added two files I am using to do unit tests.
You can not use them directly since they try to load files which you do not
have.
However you should see how to proceed.
Robert
----- Original Message -----
From: "Jean-François Ménard" <menard.jean-francois@hydro.qc.ca>
To: <zope@zope.org>
Sent: Monday, May 27, 2002 3:40 PM
Subject: [Zope] Unit testing (no html...)


> (Sorry for previous HTML message, /"!%/$?$& Outlook...)
>
> I just read Unit testing chapter of the excellent "Dive into python"
> book. (www.diveintopython.org)
>
> I know that Zope 3 development use Unit Testing modules extensibly.
>
> I wonder if anyone use Unit Testing for Zope 2.x product development?
> Any advices or insights?
>
> Wich modules do I need to import, path setting, etc.?
>
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>

------=_NextPart_000_009F_01C205A7.E96F7BB0
Content-Type: application/octet-stream;
	name="testRedPM.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="testRedPM.py"

=0A=
import unittest=0A=
from support import *=0A=
import ZODB=0A=
from Products.RedPM import RedPM=0A=
from OFS.Folder import Folder=0A=
=0A=
=0A=
class RedPMTests (unittest.TestCase):=0A=
=0A=
    def setUp(self):=0A=
        app =3D Folder('app')=0A=
        self.app =3D app=0A=
        app.site =3D Folder('site')=0A=
        pm =3D RedPM.RedPM()=0A=
        app.site.pm =3D pm=0A=
=0A=
=0A=
    def testPMBase ( self ) :=0A=
        ei =3D RedPM.PMBase(parent =3D self.app.site.pm)=0A=
        self.assertNotEqual(ei.getPid(), None)=0A=
        name=3D'Hans'=0A=
        email=3D'hans@zuhause.ch'=0A=
        ei.setName( name )=0A=
        ei.setEmail( email )=0A=
        self.assertEqual(ei.description(), '%s <%s>' % (name, email))=0A=
        # test to access the two lists=0A=
        self.assertEqual(ei.listContacts(), None)=0A=
        self.assertEqual(ei.listAddresses(), None)=0A=
=0A=
    def testAddContact(self):=0A=
        personlist =3D self.app.site.pm.getPersonlist()=0A=
        self.assertEqual(len(personlist.listAllContactsAndGroups()), 0)=0A=
        id =3D personlist.addContact(name=3D'Shane', email=3D'x@y.com')=0A=
        emails =3D personlist.listAllContactsAndGroups()=0A=
        self.assertEqual(len(emails), 1)=0A=
        self.assertEqual(emails[0]['description'], 'Shane <x@y.com>')=0A=
=0A=
    def testAddBaddContact(self):=0A=
        personlist =3D self.app.site.pm.getPersonlist()=0A=
        self.assertEqual(len(personlist.listAllContactsAndGroups()), 0)=0A=
        self.assertRaises(ValueError, =
personlist.addContact,name=3D'Shane', email=3D'x@y.com', ctype=3D99)=0A=
=0A=
=0A=
=0A=
def test_suite():=0A=
    suite =3D unittest.TestSuite()=0A=
    suite.addTest(unittest.makeSuite(RedPMTests))=0A=
    return suite=0A=
=0A=
def run():=0A=
    unittest.TextTestRunner().run(test_suite())=0A=
=0A=
if __name__ =3D=3D '__main__':=0A=
    run()=0A=

------=_NextPart_000_009F_01C205A7.E96F7BB0
Content-Type: application/octet-stream;
	name="support.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="support.py"

import os, sys=0A=
from os import environ=0A=
from sys import stdin, stdout, path=0A=
sys.path.insert(0, '..')=0A=
# here the environment is "adapted" to the several computers we are using=0A=
# on different sites=0A=
if os.name=3D=3D'posix' :=0A=
        if os.environ.has_key('ZOPE_HOME') :=0A=
                sys.path.insert(0, os.environ.get('ZOPE_HOME', =
'../../..')+'/lib/python/')=0A=
        else:=0A=
                sys.path.insert(0, '/var/lib/zope/lib/python/')=0A=
                os.environ['PRODUCTS_PATH'] =3D =
"/home/zope/Products/:/var/lib/zope/lib/Python/Products"=0A=
else:=0A=
        if os.environ['COMPUTERNAME'] =3D=3D 'P01' :=0A=
                sys.path.insert(0, 'K:/Programme/zope/lib/python/')=0A=
                os.environ['PRODUCTS_PATH'] =3D =
"g:/projects/redModules;G:/projects/CMF;g:/projects/p_path;k:/programme/z=
ope/lib/python/Products;"=0A=
        else:=0A=
                sys.path.insert(0, 'K:/Programme/zope/lib/python/')=0A=
                os.environ['PRODUCTS_PATH'] =3D =
"g:/projects/redModules;G:/projects/CMF;g:/projects/p_path;k:/programme/z=
ope/lib/python/Products;"=0A=
import Zope,Acquisition=0A=
from ZPublisher.HTTPRequest import HTTPRequest=0A=
from ZPublisher.HTTPResponse import HTTPResponse=0A=
from ZPublisher.BaseRequest import RequestContainer=0A=
from Products.RedInfopool.NuxUserGroups.UserFolderWithGroups import =
UserFolderWithGroups=0A=
=0A=

------=_NextPart_000_009F_01C205A7.E96F7BB0--