Back to index

plone3  3.1.7
test_atfavorite.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 """
00021 
00022 __author__ = 'Christian Heimes <tiran@cheimes.de>'
00023 __docformat__ = 'restructuredtext'
00024 
00025 from Testing import ZopeTestCase # side effect import. leave it here.
00026 from Products.ATContentTypes.tests import atcttestcase, atctftestcase
00027 
00028 import transaction
00029 from Products.CMFCore.permissions import View
00030 from Products.CMFCore.permissions import ModifyPortalContent
00031 from Products.CMFCore.utils import getToolByName
00032 from Products.Archetypes.interfaces.layer import ILayerContainer
00033 from Products.Archetypes.atapi import *
00034 from Products.Archetypes.tests.atsitetestcase import portal_name
00035 
00036 from Products.ATContentTypes.content.favorite import ATFavorite
00037 from Products.ATContentTypes.interfaces import IATFavorite
00038 from Interface.Verify import verifyObject
00039 
00040 # z3 imports
00041 from Products.ATContentTypes.interface import IATFavorite as Z3IATFavorite
00042 from zope.interface.verify import verifyObject as Z3verifyObject
00043 
00044 URL='/%s/Members' % portal_name
00045 
00046 def editATCT(obj):
00047     obj.setTitle('Test Title')
00048     obj.setDescription('Test description')
00049     obj.setRemoteUrl(URL)
00050     return obj
00051 
00052 tests = []
00053 
00054 class TestSiteATFavorite(atcttestcase.ATCTTypeTestCase):
00055 
00056     klass = ATFavorite
00057     portal_type = 'Favorite'
00058     title = 'Favorite'
00059     meta_type = 'ATFavorite'
00060     icon = 'favorite_icon.gif'
00061 
00062     def test_implementsZ3ATFavorite(self):
00063         iface = Z3IATFavorite
00064         self.failUnless(Z3verifyObject(iface, self._ATCT))
00065 
00066     def test_implementsATFavorite(self):
00067         iface = IATFavorite
00068         self.failUnless(iface.isImplementedBy(self._ATCT))
00069         self.failUnless(verifyObject(iface, self._ATCT))
00070 
00071     def testLink(self):
00072         obj = self._ATCT
00073         for url in ('', '/test/',):
00074             obj.setRemoteUrl(url)
00075             u = self.portal.portal_url()
00076             if url.startswith('/'):
00077                 url = url[1:]
00078             if url:
00079                 u='%s/%s' % (u, url)
00080             self.failUnlessEqual(obj.getRemoteUrl(), u)
00081 
00082     def test_get_size(self):
00083         atct = self._ATCT
00084         editATCT(atct)
00085         # url is /plone/Members but the favorite stores the url relative to
00086         # the portal so substract length of the portal + 2 for the two slashes
00087         url_len = len(URL) - len(portal_name) - 2
00088         self.failUnlessEqual(atct.get_size(), url_len)
00089 
00090 tests.append(TestSiteATFavorite)
00091 
00092 class TestATFavoriteFields(atcttestcase.ATCTFieldTestCase):
00093 
00094     def afterSetUp(self):
00095         atcttestcase.ATCTFieldTestCase.afterSetUp(self)
00096         self._dummy = self.createDummy(klass=ATFavorite)
00097 
00098     def test_remoteUrlField(self):
00099         dummy = self._dummy
00100         field = dummy.getField('remoteUrl')
00101 
00102         self.failUnless(ILayerContainer.isImplementedBy(field))
00103         self.failUnless(field.required == 1, 'Value is %s' % field.required)
00104         self.failUnless(field.default == '', 'Value is %s' % str(field.default))
00105         self.failUnless(field.searchable == 1, 'Value is %s' % field.searchable)
00106         self.failUnless(field.vocabulary == (),
00107                         'Value is %s' % str(field.vocabulary))
00108         self.failUnless(field.enforceVocabulary == 0,
00109                         'Value is %s' % field.enforceVocabulary)
00110         self.failUnless(field.multiValued == 0,
00111                         'Value is %s' % field.multiValued)
00112         self.failUnless(field.isMetadata == 0, 'Value is %s' % field.isMetadata)
00113         self.failUnless(field.accessor == '_getRemoteUrl',
00114                         'Value is %s' % field.accessor)
00115         self.failUnless(field.mutator == 'setRemoteUrl',
00116                         'Value is %s' % field.mutator)
00117         self.failUnless(field.read_permission == View,
00118                         'Value is %s' % field.read_permission)
00119         self.failUnless(field.write_permission == ModifyPortalContent,
00120                         'Value is %s' % field.write_permission)
00121         self.failUnless(field.generateMode == 'veVc',
00122                         'Value is %s' % field.generateMode)
00123         self.failUnless(field.force == '', 'Value is %s' % field.force)
00124         self.failUnless(field.type == 'string', 'Value is %s' % field.type)
00125         self.failUnless(isinstance(field.storage, AttributeStorage),
00126                         'Value is %s' % type(field.storage))
00127         self.failUnless(field.getLayerImpl('storage') == AttributeStorage(),
00128                         'Value is %s' % field.getLayerImpl('storage'))
00129         self.failUnless(ILayerContainer.isImplementedBy(field))
00130         self.failUnless(field.validators == (),
00131                         'Value is %s' % str(field.validators))
00132         self.failUnless(isinstance(field.widget, StringWidget),
00133                         'Value is %s' % id(field.widget))
00134         vocab = field.Vocabulary(dummy)
00135         self.failUnless(isinstance(vocab, DisplayList),
00136                         'Value is %s' % type(vocab))
00137         self.failUnless(tuple(vocab) == (), 'Value is %s' % str(tuple(vocab)))
00138         self.failUnless(field.primary == 1, 'Value is %s' % field.primary)
00139 
00140 tests.append(TestATFavoriteFields)
00141 
00142 class TestATFavoriteFunctional(atctftestcase.ATCTIntegrationTestCase):
00143     
00144     portal_type = 'Favorite'
00145     views = ('favorite_view', )
00146 
00147 tests.append(TestATFavoriteFunctional)
00148 
00149 import unittest
00150 def test_suite():
00151     suite = unittest.TestSuite()
00152     for test in tests:
00153         suite.addTest(unittest.makeSuite(test))
00154     return suite