Re: [Zope] unittest a component that is using zope.dublincore

2009-03-30 Thread Thierry Florac
Le samedi 28 mars 2009 à 15:46 +0100, Jean-Michel FRANCOIS a écrit :
 Hi,
   I m trying to make my first content type with zope3. The code is
 available there: http://github.com/toutpt/z3weblog.entry/tree
 
 I m following the second edition of the book web component developement
 with zope3, i know this is not the last edition. So, i m making a
 ISized component for my simple content type, with a simple unittest, but
 now, i want to use zope.dublincore package and i get an error when i m
 launch the tests:
 
 =
 (zope3apps)tou...@linux-tggd:~/workspace/zope3apps/apps/prout .bin/test
 Running tests at level 1
 Running unit tests:
   Running:
 ...
 
 Error in test test_size_for_display
 (z3weblog.entry.tests.test_size.EntrySizeTestCase)
 Traceback (most recent call last):
   File
 /home/toutpt/outils/python_system/2.5.4/lib/python2.5/unittest.py,
 line 260, in run
 testMethod()
   File
 /home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/tests/test_size.py,
 line 21, in test_size_for_display
 msg = self.size.sizeForDisplay()
   File
 /home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
 line 24, in sizeForDisplay
 unit, chars = self.sizeForSorting()
   File
 /home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
 line 18, in sizeForSorting
 dc = dcI.IZopeDublinCore(self.context)
 TypeError: ('Could not adapt', z3weblog.entry.content.ZODBWeblogEntry
 object at 0x839382c, InterfaceClass
 zope.dublincore.interfaces.IZopeDublinCore)
 
 .
 
 Error in test test_size_for_sorting
 (z3weblog.entry.tests.test_size.EntrySizeTestCase)
 Traceback (most recent call last):
   File
 /home/toutpt/outils/python_system/2.5.4/lib/python2.5/unittest.py,
 line 260, in run
 testMethod()
   File
 /home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/tests/test_size.py,
 line 16, in test_size_for_sorting
 unit, size = self.size.sizeForSorting()
   File
 /home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
 line 18, in sizeForSorting
 dc = dcI.IZopeDublinCore(self.context)
 TypeError: ('Could not adapt', z3weblog.entry.content.ZODBWeblogEntry
 object at 0x839382c, InterfaceClass
 zope.dublincore.interfaces.IZopeDublinCore)
 
 
   Ran 4 tests with 0 failures and 2 errors in 0.007 seconds.
 
 Tests with errors:
test_size_for_display (z3weblog.entry.tests.test_size.EntrySizeTestCase)
test_size_for_sorting (z3weblog.entry.tests.test_size.EntrySizeTestCase)
 
 
 
 The trace back is very clear, the zope.dublincore components are not
 loaded. The question is : what is the best way to load components in
 unittests ? Do just i have to load the zcml of zope.dublincore, or do i
 have to register only needed components, if so how can i do that ?


You can also provide your own adapter and register it for your tests.
This example is extracted from zope.app.container unit tests :


from datetime import datetime
from zope.security import checker
from zope.dublincore.interfaces import IZopeDublinCore
from zope.app.testing import ztapi

class EntrySizeTestCase(unittest.TestCase):

def setUp(self):
class FauxDCAdapter(object):
implements(IZopeDublinCore)

__Security_checker__ = checker.Checker(
{created: zope.Public,
 modified: zope.Public,
 title: zope.Public,
 },
{title: zope.app.dublincore.change})

def __init__(self, context):
pass
title = 'faux title'
size = 1024
created = datetime(2001, 1, 1, 1, 1, 1)
modified = datetime(2002, 2, 2, 2, 2, 2)

ztapi.provideAdapter(IZODBWeblogEntry, IZopeDublinCore,
FauxDCAdapter)


Not tested anyway, but hope will help...

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.flo...@onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


[Zope] unittest a component that is using zope.dublincore

2009-03-28 Thread Jean-Michel FRANCOIS
Hi,
  I m trying to make my first content type with zope3. The code is
available there: http://github.com/toutpt/z3weblog.entry/tree

I m following the second edition of the book web component developement
with zope3, i know this is not the last edition. So, i m making a
ISized component for my simple content type, with a simple unittest, but
now, i want to use zope.dublincore package and i get an error when i m
launch the tests:

=
(zope3apps)tou...@linux-tggd:~/workspace/zope3apps/apps/prout .bin/test
Running tests at level 1
Running unit tests:
  Running:
...

Error in test test_size_for_display
(z3weblog.entry.tests.test_size.EntrySizeTestCase)
Traceback (most recent call last):
  File
/home/toutpt/outils/python_system/2.5.4/lib/python2.5/unittest.py,
line 260, in run
testMethod()
  File
/home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/tests/test_size.py,
line 21, in test_size_for_display
msg = self.size.sizeForDisplay()
  File
/home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
line 24, in sizeForDisplay
unit, chars = self.sizeForSorting()
  File
/home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
line 18, in sizeForSorting
dc = dcI.IZopeDublinCore(self.context)
TypeError: ('Could not adapt', z3weblog.entry.content.ZODBWeblogEntry
object at 0x839382c, InterfaceClass
zope.dublincore.interfaces.IZopeDublinCore)

.

Error in test test_size_for_sorting
(z3weblog.entry.tests.test_size.EntrySizeTestCase)
Traceback (most recent call last):
  File
/home/toutpt/outils/python_system/2.5.4/lib/python2.5/unittest.py,
line 260, in run
testMethod()
  File
/home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/tests/test_size.py,
line 16, in test_size_for_sorting
unit, size = self.size.sizeForSorting()
  File
/home/toutpt/workspace/zope3apps/apps/prout/src/z3weblog.entry/src/z3weblog/entry/size.py,
line 18, in sizeForSorting
dc = dcI.IZopeDublinCore(self.context)
TypeError: ('Could not adapt', z3weblog.entry.content.ZODBWeblogEntry
object at 0x839382c, InterfaceClass
zope.dublincore.interfaces.IZopeDublinCore)


  Ran 4 tests with 0 failures and 2 errors in 0.007 seconds.

Tests with errors:
   test_size_for_display (z3weblog.entry.tests.test_size.EntrySizeTestCase)
   test_size_for_sorting (z3weblog.entry.tests.test_size.EntrySizeTestCase)



The trace back is very clear, the zope.dublincore components are not
loaded. The question is : what is the best way to load components in
unittests ? Do just i have to load the zcml of zope.dublincore, or do i
have to register only needed components, if so how can i do that ?

JeanMichel FRANCOIS
Makina-Corpus
begin:vcard
fn:JeanMichel FRANCOIS
n:FRANCOIS;JeanMichel
org:Makina-Corpus
adr;quoted-printable:;;44 boulevard des pas enchant=C3=A9s;Nantes;;44200;FRANCE
email;internet:jeanmichel.franc...@makina-corpus.com
title;quoted-printable:Ing=C3=A9nieur D=C3=A9veloppement
tel;work:0251798084
tel;home:0240133880
tel;cell:0675156788
url:www.makina-corpus.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )