[Checkins] SVN: grokapps/kirbi/trunk/src/kirbi/ Fixed the setting of the book source when done through the adding form and added a doctest for it. Some other minor cleanups.

Luciano Ramalho luciano at ramalho.org
Tue Sep 11 23:02:51 EDT 2007


Log message for revision 79580:
  Fixed the setting of the book source when done through the adding form and added a doctest for it. Some other minor cleanups.

Changed:
  A   grokapps/kirbi/trunk/src/kirbi/ftests/addbook.txt
  U   grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py
  U   grokapps/kirbi/trunk/src/kirbi/interfaces.py
  U   grokapps/kirbi/trunk/src/kirbi/isbn.py
  U   grokapps/kirbi/trunk/src/kirbi/pac.py

-=-
Added: grokapps/kirbi/trunk/src/kirbi/ftests/addbook.txt
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/addbook.txt	                        (rev 0)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/addbook.txt	2007-09-12 03:02:51 UTC (rev 79580)
@@ -0,0 +1,27 @@
+============================
+Testing the Book adding form
+============================
+
+First we setup the app and our test browser, navigating to the book adding
+form::
+
+    >>> from kirbi.app import Kirbi
+    >>> root = getRootFolder()
+    >>> root['kirbi'] = Kirbi()
+    >>> pac = root['kirbi']['pac']
+    >>> browser = Browser()
+    >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
+    >>> browser.handleErrors = False
+    >>> browser.open('http://localhost/kirbi/pac/addbook')                 
+
+Now we add a book through this form::
+
+    >>> browser.getControl('Title').value = "One Flew Over the Cuckoo's Nest"
+    >>> browser.getControl('Save book').click()
+
+And we can see the book has 'source' set to the user who originated this book,
+since the details were manually entered::
+
+    >>> book, = pac.values()
+    >>> print book.source
+    zope.mgr

Modified: grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py	2007-09-12 00:47:27 UTC (rev 79579)
+++ grokapps/kirbi/trunk/src/kirbi/ftests/test_functional.py	2007-09-12 03:02:51 UTC (rev 79580)
@@ -20,7 +20,11 @@
 
 def test_suite():
     suite = unittest.TestSuite()
-    docfiles = ['xmlrpc.txt', 'user.txt', 'learning.txt']
+    docfiles = ['xmlrpc.txt',
+                'user.txt',
+                'learning.txt',
+                'addbook.txt',
+                ]
 
     for docfile in docfiles:
         test = FunctionalDocFileSuite(

Modified: grokapps/kirbi/trunk/src/kirbi/interfaces.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/interfaces.py	2007-09-12 00:47:27 UTC (rev 79579)
+++ grokapps/kirbi/trunk/src/kirbi/interfaces.py	2007-09-12 03:02:51 UTC (rev 79580)
@@ -37,9 +37,6 @@
 
 class InvalidISBN(schema.ValidationError):
     """This is not a valid ISBN-10 or ISBN-13"""
-    ### XXX: There is another exception class with the same name in
-    ### isbn.py. I'd like to avoid the duplication, but how to do it
-    ### without making the isbn.py module depend on schema.ValidationError?
 
 def validateISBN(isbn):
     if not isValidISBN(isbn):

Modified: grokapps/kirbi/trunk/src/kirbi/isbn.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/isbn.py	2007-09-12 00:47:27 UTC (rev 79579)
+++ grokapps/kirbi/trunk/src/kirbi/isbn.py	2007-09-12 03:02:51 UTC (rev 79580)
@@ -16,9 +16,6 @@
 
 class InvalidISBN(ValueError):
     """This is not a valid ISBN-10 or ISBN-13"""
-    ### XXX: There is another exception class with the same name in
-    ### interfaces.py. I'd like to avoid the duplication, but how to do it
-    ### without making this module depend on schema.ValidationError?
 
 def filterDigits(input):
     """ Strip the input of all non-digits, but retain last X if present. """

Modified: grokapps/kirbi/trunk/src/kirbi/pac.py
===================================================================
--- grokapps/kirbi/trunk/src/kirbi/pac.py	2007-09-12 00:47:27 UTC (rev 79579)
+++ grokapps/kirbi/trunk/src/kirbi/pac.py	2007-09-12 03:02:51 UTC (rev 79580)
@@ -164,12 +164,13 @@
     template = grok.PageTemplateFile('form.pt')
     form_title = u'Add book'
 
-    @grok.action('Save book')
+    @grok.action('Save book', name='save')
     def add(self, **data):
-        ### XXX: investigate why the source data is not being recorded
-        data['source'] = self.request.principal.id
         book = Book()
         self.applyData(book, **data)
+        # we manually set the source here since this was a manually added
+        # book. I.e. the "information source" is the user herself.
+        book.source = unicode(self.request.principal.id)
         self.context.addBook(book)
         self.redirect(self.url(self.context))
 



More information about the Checkins mailing list