icsemantic.catalog.tests.base

Package platecom :: Package ontocatalog :: Package tests :: Module base |
[hide private]
[frames] | no frames]

# Source Code for Module icsemantic.catalog.tests.base

      1  """Test setup for unit, integration and functional tests.
      2
      3  When we import PloneTestCase and then call setupPloneSite(), all of Plone's
      4  products are loaded, and a Plone site will be created. This happens at module
      5  level, which makes it faster to run each test, but slows down test runner
      6  startup.
      7  """
      8  import os, sys
      9  from App import Common
     10
     11  from zope.component import queryUtility
     12
     13  from Products.Five import zcml
     14  from Products.Five import fiveconfigure
     15
     16  from Testing import ZopeTestCase as ztc
     17
     18  from Products.PloneTestCase import PloneTestCase as ptc
     19  from Products.PloneTestCase.layer import onsetup
     20
     21  from platecom.ontoplone.interfaces.IThesaurus import IThesaurus
     22  from platecom.ontocatalog.config import *
     23  from pythesaurus.Concept import Concept
     24
     25  from platecom.langview.tests import utils
     26
     27  #
     28  # When ZopeTestCase configures Zope, it will *not* auto-load products in
     29  # Products/. Instead, we have to use a statement such as:
     30  #
     31  #   ztc.installProduct('SimpleAttachment')
     32  #
     33  # This does *not* apply to products in eggs and Python packages (i.e. not in
     34  # the Products.*) namespace. For that, see below.
     35  #
     36  # All of Plone's products are already set up by PloneTestCase.
     37  #
     38
     39  if not HAS_PLONE3:
     40      ztc.installProduct('PloneLanguageTool')
     41
     42  ztc.installProduct('LinguaPlone')
     43  ztc.installProduct('pluggablecatalog')
     44
     45  @onsetup
     46 -def setup_icsemantic.catalog():
     47      ztc.installProduct('Five')
     48      fiveconfigure.debug_mode = True
     49      zcml.load_config('configure.zcml', PACKAGE)
     50      fiveconfigure.debug_mode = False
     51
     52      # XXX monkey patch everytime (until we figure out the problem where
     53      # monkeypatch gets overwritten somewhere)
     54      try:
     55          from Products.Five import pythonproducts
     56          pythonproducts.setupPythonProducts(None)
     57
     58          # MONKEYPATCH: arregla los problemas con el
     59          # control panel y la instalacion de Five...
     60          import App
     61          App.ApplicationManager.ApplicationManager.Five=utils.Five
     62
     63          # MONKEYPATCH: arregla los problemas con el
     64          # HTTP_REFERER en los tests funcionales. Tiene la
     65          # contra de enviarnos al raiz del plone cada vez
     66          # que un metodo depende de esa variable, pero es
     67          # mejor que morir con una excepcion o llenar los
     68          # tests de try blocks...
     69          ztc.zopedoctest.functional.http=utils.http
     70
     71
     72      except ImportError:
     73          # Not needed in Plone 3
     74          ztc.installPackage('icsemantic.core')
     75          ztc.installPackage('icsemantic.langfallback')
     76          ztc.installPackage('icsemantic.thesaurus')
     77          ztc.installPackage(PROJECTNAME)
     78          pass
     79
     80  setup_icsemantic.catalog()
     81
     82  ptc.setupPloneSite(products=[PROJECTNAME,])
     83
     84 -def add_test_thesaurus(portal):
     85      """Fill the thesaurus local utility with some useful information"""
     86      t = portal.utilities.IThesaurus
     87      c = Concept(et = ["fÃºtbol@es", "balÃ³n pie@es", "soccer@en", "football@en",
     88                        "football@fr"])
     89      t.append_concept(c)
     90      t.append_term("mundial@es", rt=["fÃºtbol@es"])
     91
     92
     93 -class OntoCatalogTestCase(ptc.PloneTestCase):
     94      """We use this base class for all the tests in this package. If necessary,
     95      we can put common utility or setup code in here. This applies to unit
     96      test cases.
     97      """
     98 -    def setUp(self):
     99          super(ptc.PloneTestCase, self).setUp()
    100          #add_test_thesaurus(self.portal)
    101
    102
    103 -class OntoCatalogFunctionalTestCase(ptc.FunctionalTestCase):
    104      """We use this class for functional integration tests that use doctest
    105      syntax. Again, we can put basic common utility or setup code in here.
    106      """
    107 -    def setUp(self):
    108          super(ptc.FunctionalTestCase, self).setUp()
    109          add_test_thesaurus(self.portal)
    110