Back to index

plone3  3.1.7
Classes | Functions
GenericSetup.tests.test_zcml Namespace Reference

Classes

class  ImportStepTests
class  ExportStepTests

Functions

def dummy_importstep_handler
def dummy_exportstep_handler
def dummy_upgrade_handler
def b_dummy_upgrade_handler
def c_dummy_upgrade_handler
def test_simpleRegisterProfile
def test_registerProfile
def test_registerUpgradeStep
def test_registerUpgradeSteps
def test_suite

Function Documentation

Definition at line 37 of file test_zcml.py.

00037 
00038 def b_dummy_upgrade_handler(context):
00039     pass

Definition at line 40 of file test_zcml.py.

00040 
00041 def c_dummy_upgrade_handler(context):
00042     pass

Definition at line 31 of file test_zcml.py.

00031 
00032 def dummy_exportstep_handler(context):
00033     pass

Definition at line 28 of file test_zcml.py.

00028 
00029 def dummy_importstep_handler(context):
00030     pass

Definition at line 34 of file test_zcml.py.

00034 
00035 def dummy_upgrade_handler(context):
00036     pass

Use the genericsetup:registerProfile directive::

  >>> import Products.GenericSetup
  >>> from Products.Five import zcml
  >>> configure_zcml = '''
  ... <configure
  ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
  ...     i18n_domain="foo">
  ...   <genericsetup:registerProfile
  ...       name="default"
  ...       title="Install Foo Extension"
  ...       description="Adds foo support."
  ...       provides="Products.GenericSetup.interfaces.EXTENSION"
  ...       />
  ... </configure>'''
  >>> zcml.load_config('meta.zcml', Products.GenericSetup)
  >>> zcml.load_string(configure_zcml)

Make sure the profile is registered correctly::

  >>> from Products.GenericSetup.registry import _profile_registry
  >>> profile_id = 'Products.GenericSetup:default'
  >>> profile_id in _profile_registry._profile_ids
  True
  >>> info = _profile_registry._profile_info[profile_id]
  >>> info['id']
  u'Products.GenericSetup:default'
  >>> info['title']
  u'Install Foo Extension'
  >>> info['description']
  u'Adds foo support.'
  >>> info['path']
  u'profiles/default'
  >>> info['product']
  'Products.GenericSetup'
  >>> from Products.GenericSetup.interfaces import EXTENSION
  >>> info['type'] is EXTENSION
  True
  >>> info['for'] is None
  True

Clean up and make sure the cleanup works::

  >>> from zope.testing.cleanup import cleanUp
  >>> cleanUp()
  >>> profile_id in _profile_registry._profile_ids
  False
  >>> profile_id in _profile_registry._profile_info
  False

Definition at line 93 of file test_zcml.py.

00093 
00094 def test_registerProfile():
00095     """
00096     Use the genericsetup:registerProfile directive::
00097 
00098       >>> import Products.GenericSetup
00099       >>> from Products.Five import zcml
00100       >>> configure_zcml = '''
00101       ... <configure
00102       ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
00103       ...     i18n_domain="foo">
00104       ...   <genericsetup:registerProfile
00105       ...       name="default"
00106       ...       title="Install Foo Extension"
00107       ...       description="Adds foo support."
00108       ...       provides="Products.GenericSetup.interfaces.EXTENSION"
00109       ...       />
00110       ... </configure>'''
00111       >>> zcml.load_config('meta.zcml', Products.GenericSetup)
00112       >>> zcml.load_string(configure_zcml)
00113 
00114     Make sure the profile is registered correctly::
00115 
00116       >>> from Products.GenericSetup.registry import _profile_registry
00117       >>> profile_id = 'Products.GenericSetup:default'
00118       >>> profile_id in _profile_registry._profile_ids
00119       True
00120       >>> info = _profile_registry._profile_info[profile_id]
00121       >>> info['id']
00122       u'Products.GenericSetup:default'
00123       >>> info['title']
00124       u'Install Foo Extension'
00125       >>> info['description']
00126       u'Adds foo support.'
00127       >>> info['path']
00128       u'profiles/default'
00129       >>> info['product']
00130       'Products.GenericSetup'
00131       >>> from Products.GenericSetup.interfaces import EXTENSION
00132       >>> info['type'] is EXTENSION
00133       True
00134       >>> info['for'] is None
00135       True
00136 
00137     Clean up and make sure the cleanup works::
00138 
00139       >>> from zope.testing.cleanup import cleanUp
00140       >>> cleanUp()
00141       >>> profile_id in _profile_registry._profile_ids
00142       False
00143       >>> profile_id in _profile_registry._profile_info
00144       False
00145     """

Use the genericsetup:upgradeStep directive::

  >>> import Products.GenericSetup
  >>> from Products.Five import zcml
  >>> configure_zcml = '''
  ... <configure
  ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
  ...     i18n_domain="foo">
  ...   <genericsetup:upgradeStep
  ...       title="Upgrade Foo Product"
  ...       description="Upgrades Foo from 1.0 to 1.1."
  ...       source="1.0"
  ...       destination="1.1"
  ...       handler="Products.GenericSetup.tests.test_zcml.dummy_upgrade_handler"
  ...       sortkey="1"
  ...       profile="default"
  ...       />
  ... </configure>'''
  >>> zcml.load_config('meta.zcml', Products.GenericSetup)
  >>> zcml.load_string(configure_zcml)

Make sure the upgrade step is registered correctly::

  >>> from Products.GenericSetup.upgrade import _upgrade_registry
  >>> profile_steps = _upgrade_registry.getUpgradeStepsForProfile('default')
  >>> keys = profile_steps.keys()
  >>> len(keys)
  1
  >>> step = profile_steps[keys[0]]
  >>> step.source
  ('1', '0')
  >>> step.dest
  ('1', '1')
  >>> step.handler
  <function dummy_upgrade_handler at ...>

Clean up and make sure the cleanup works::

  >>> from zope.testing.cleanup import cleanUp
  >>> cleanUp()

Definition at line 146 of file test_zcml.py.

00146 
00147 def test_registerUpgradeStep(self):
00148     """
00149     Use the genericsetup:upgradeStep directive::
00150 
00151       >>> import Products.GenericSetup
00152       >>> from Products.Five import zcml
00153       >>> configure_zcml = '''
00154       ... <configure
00155       ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
00156       ...     i18n_domain="foo">
00157       ...   <genericsetup:upgradeStep
00158       ...       title="Upgrade Foo Product"
00159       ...       description="Upgrades Foo from 1.0 to 1.1."
00160       ...       source="1.0"
00161       ...       destination="1.1"
00162       ...       handler="Products.GenericSetup.tests.test_zcml.dummy_upgrade_handler"
00163       ...       sortkey="1"
00164       ...       profile="default"
00165       ...       />
00166       ... </configure>'''
00167       >>> zcml.load_config('meta.zcml', Products.GenericSetup)
00168       >>> zcml.load_string(configure_zcml)
00169 
00170     Make sure the upgrade step is registered correctly::
00171 
00172       >>> from Products.GenericSetup.upgrade import _upgrade_registry
00173       >>> profile_steps = _upgrade_registry.getUpgradeStepsForProfile('default')
00174       >>> keys = profile_steps.keys()
00175       >>> len(keys)
00176       1
00177       >>> step = profile_steps[keys[0]]
00178       >>> step.source
00179       ('1', '0')
00180       >>> step.dest
00181       ('1', '1')
00182       >>> step.handler
00183       <function dummy_upgrade_handler at ...>
00184 
00185     Clean up and make sure the cleanup works::
00186 
00187       >>> from zope.testing.cleanup import cleanUp
00188       >>> cleanUp()
00189     """
00190 

Use the nested genericsetup:upgradeSteps directive::

  >>> import Products.GenericSetup
  >>> from Products.Five import zcml
  >>> configure_zcml = '''
  ... <configure
  ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
  ...     i18n_domain="foo">
  ...   <genericsetup:upgradeSteps
  ...       profile="default"
  ...       source="1.0"
  ...       destination="1.1"
  ...       sortkey="2"
  ...       >
  ...       <genericsetup:upgradeStep
  ...           title="Foo Upgrade Step 1"
  ...           description="Does some Foo upgrade thing."
  ...           handler="Products.GenericSetup.tests.test_zcml.b_dummy_upgrade_handler"
  ...           />
  ...       <genericsetup:upgradeStep
  ...           title="Foo Upgrade Step 2"
  ...           description="Does another Foo upgrade thing."
  ...           handler="Products.GenericSetup.tests.test_zcml.c_dummy_upgrade_handler"
  ...           />
  ...   </genericsetup:upgradeSteps>
  ...   <genericsetup:upgradeSteps
  ...       profile="default"
  ...       source="1.0"
  ...       destination="1.1"
  ...       sortkey="1"
  ...       >
  ...       <genericsetup:upgradeStep
  ...           title="Bar Upgrade Step 1"
  ...           description="Does some Bar upgrade thing."
  ...           handler="Products.GenericSetup.tests.test_zcml.b_dummy_upgrade_handler"
  ...           />
  ...       <genericsetup:upgradeStep
  ...           title="Bar Upgrade Step 2"
  ...           description="Does another Bar upgrade thing."
  ...           handler="Products.GenericSetup.tests.test_zcml.c_dummy_upgrade_handler"
  ...           />
  ...   </genericsetup:upgradeSteps>
  ... </configure>'''
  >>> zcml.load_config('meta.zcml', Products.GenericSetup)
  >>> zcml.load_string(configure_zcml)

Make sure the upgrade steps are registered correctly::

  >>> from Products.GenericSetup.upgrade import _upgrade_registry
  >>> from Products.GenericSetup.upgrade import listUpgradeSteps
  >>> from Products.GenericSetup.tool import SetupTool
  >>> tool = SetupTool('setup_tool')
  >>> profile_steps = listUpgradeSteps(tool, 'default', '1.0')
  >>> len(profile_steps)
  2
  >>> steps = profile_steps[0]
  >>> type(steps)
  <type 'list'>
  >>> len(steps)
  2
  >>> step1, step2 = steps
  >>> step1['source'] == step2['source'] == ('1', '0')
  True
  >>> step1['dest'] == step2['dest'] == ('1', '1')
  True
  >>> step1['step'].handler
  <function b_dummy_upgrade_handler at ...>
  >>> step1['title']
  u'Bar Upgrade Step 1'
  >>> step2['step'].handler
  <function c_dummy_upgrade_handler at ...>
  >>> step2['title']
  u'Bar Upgrade Step 2'
  
First one listed should be second in the registry due to sortkey:

  >>> steps = profile_steps[1]
  >>> type(steps)
  <type 'list'>
  >>> len(steps)
  2
  >>> step1, step2 = steps
  >>> step1['source'] == step2['source'] == ('1', '0')
  True
  >>> step1['dest'] == step2['dest'] == ('1', '1')
  True
  >>> step1['step'].handler
  <function b_dummy_upgrade_handler at ...>
  >>> step1['title']
  u'Foo Upgrade Step 1'
  >>> step2['step'].handler
  <function c_dummy_upgrade_handler at ...>
  >>> step2['title']
  u'Foo Upgrade Step 2'

Clean up and make sure the cleanup works::

  >>> from zope.testing.cleanup import cleanUp
  >>> cleanUp()

Definition at line 191 of file test_zcml.py.

00191 
00192 def test_registerUpgradeSteps(self):
00193     """
00194     Use the nested genericsetup:upgradeSteps directive::
00195 
00196       >>> import Products.GenericSetup
00197       >>> from Products.Five import zcml
00198       >>> configure_zcml = '''
00199       ... <configure
00200       ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
00201       ...     i18n_domain="foo">
00202       ...   <genericsetup:upgradeSteps
00203       ...       profile="default"
00204       ...       source="1.0"
00205       ...       destination="1.1"
00206       ...       sortkey="2"
00207       ...       >
00208       ...       <genericsetup:upgradeStep
00209       ...           title="Foo Upgrade Step 1"
00210       ...           description="Does some Foo upgrade thing."
00211       ...           handler="Products.GenericSetup.tests.test_zcml.b_dummy_upgrade_handler"
00212       ...           />
00213       ...       <genericsetup:upgradeStep
00214       ...           title="Foo Upgrade Step 2"
00215       ...           description="Does another Foo upgrade thing."
00216       ...           handler="Products.GenericSetup.tests.test_zcml.c_dummy_upgrade_handler"
00217       ...           />
00218       ...   </genericsetup:upgradeSteps>
00219       ...   <genericsetup:upgradeSteps
00220       ...       profile="default"
00221       ...       source="1.0"
00222       ...       destination="1.1"
00223       ...       sortkey="1"
00224       ...       >
00225       ...       <genericsetup:upgradeStep
00226       ...           title="Bar Upgrade Step 1"
00227       ...           description="Does some Bar upgrade thing."
00228       ...           handler="Products.GenericSetup.tests.test_zcml.b_dummy_upgrade_handler"
00229       ...           />
00230       ...       <genericsetup:upgradeStep
00231       ...           title="Bar Upgrade Step 2"
00232       ...           description="Does another Bar upgrade thing."
00233       ...           handler="Products.GenericSetup.tests.test_zcml.c_dummy_upgrade_handler"
00234       ...           />
00235       ...   </genericsetup:upgradeSteps>
00236       ... </configure>'''
00237       >>> zcml.load_config('meta.zcml', Products.GenericSetup)
00238       >>> zcml.load_string(configure_zcml)
00239 
00240     Make sure the upgrade steps are registered correctly::
00241 
00242       >>> from Products.GenericSetup.upgrade import _upgrade_registry
00243       >>> from Products.GenericSetup.upgrade import listUpgradeSteps
00244       >>> from Products.GenericSetup.tool import SetupTool
00245       >>> tool = SetupTool('setup_tool')
00246       >>> profile_steps = listUpgradeSteps(tool, 'default', '1.0')
00247       >>> len(profile_steps)
00248       2
00249       >>> steps = profile_steps[0]
00250       >>> type(steps)
00251       <type 'list'>
00252       >>> len(steps)
00253       2
00254       >>> step1, step2 = steps
00255       >>> step1['source'] == step2['source'] == ('1', '0')
00256       True
00257       >>> step1['dest'] == step2['dest'] == ('1', '1')
00258       True
00259       >>> step1['step'].handler
00260       <function b_dummy_upgrade_handler at ...>
00261       >>> step1['title']
00262       u'Bar Upgrade Step 1'
00263       >>> step2['step'].handler
00264       <function c_dummy_upgrade_handler at ...>
00265       >>> step2['title']
00266       u'Bar Upgrade Step 2'
00267       
00268     First one listed should be second in the registry due to sortkey:
00269 
00270       >>> steps = profile_steps[1]
00271       >>> type(steps)
00272       <type 'list'>
00273       >>> len(steps)
00274       2
00275       >>> step1, step2 = steps
00276       >>> step1['source'] == step2['source'] == ('1', '0')
00277       True
00278       >>> step1['dest'] == step2['dest'] == ('1', '1')
00279       True
00280       >>> step1['step'].handler
00281       <function b_dummy_upgrade_handler at ...>
00282       >>> step1['title']
00283       u'Foo Upgrade Step 1'
00284       >>> step2['step'].handler
00285       <function c_dummy_upgrade_handler at ...>
00286       >>> step2['title']
00287       u'Foo Upgrade Step 2'
00288 
00289     Clean up and make sure the cleanup works::
00290 
00291       >>> from zope.testing.cleanup import cleanUp
00292       >>> cleanUp()
00293     """
00294 

Use the genericsetup:registerProfile directive::

  >>> import Products.GenericSetup
  >>> from Products.Five import zcml
  >>> configure_zcml = '''
  ... <configure
  ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
  ...     i18n_domain="foo">
  ...   <genericsetup:registerProfile
  ...       provides="Products.GenericSetup.interfaces.EXTENSION"
  ...       />
  ... </configure>'''
  >>> zcml.load_config('meta.zcml', Products.GenericSetup)
  >>> zcml.load_string(configure_zcml)

Make sure the profile is registered correctly::

  >>> from Products.GenericSetup.registry import _profile_registry
  >>> profile_id = 'Products.GenericSetup:default'
  >>> profile_id in _profile_registry._profile_ids
  True
  >>> info = _profile_registry._profile_info[profile_id]
  >>> info['id']
  u'Products.GenericSetup:default'
  >>> info['title']
  u"Profile 'default' from 'Products.GenericSetup'"
  >>> info['description']
  u''
  >>> info['path']
  u'profiles/default'
  >>> info['product']
  'Products.GenericSetup'
  >>> from Products.GenericSetup.interfaces import EXTENSION
  >>> info['type'] is EXTENSION
  True
  >>> info['for'] is None
  True

Clean up and make sure the cleanup works::

  >>> from zope.testing.cleanup import cleanUp
  >>> cleanUp()
  >>> profile_id in _profile_registry._profile_ids
  False
  >>> profile_id in _profile_registry._profile_info
  False

Definition at line 43 of file test_zcml.py.

00043 
00044 def test_simpleRegisterProfile():
00045     """
00046     Use the genericsetup:registerProfile directive::
00047 
00048       >>> import Products.GenericSetup
00049       >>> from Products.Five import zcml
00050       >>> configure_zcml = '''
00051       ... <configure
00052       ...     xmlns:genericsetup="http://namespaces.zope.org/genericsetup"
00053       ...     i18n_domain="foo">
00054       ...   <genericsetup:registerProfile
00055       ...       provides="Products.GenericSetup.interfaces.EXTENSION"
00056       ...       />
00057       ... </configure>'''
00058       >>> zcml.load_config('meta.zcml', Products.GenericSetup)
00059       >>> zcml.load_string(configure_zcml)
00060 
00061     Make sure the profile is registered correctly::
00062 
00063       >>> from Products.GenericSetup.registry import _profile_registry
00064       >>> profile_id = 'Products.GenericSetup:default'
00065       >>> profile_id in _profile_registry._profile_ids
00066       True
00067       >>> info = _profile_registry._profile_info[profile_id]
00068       >>> info['id']
00069       u'Products.GenericSetup:default'
00070       >>> info['title']
00071       u"Profile 'default' from 'Products.GenericSetup'"
00072       >>> info['description']
00073       u''
00074       >>> info['path']
00075       u'profiles/default'
00076       >>> info['product']
00077       'Products.GenericSetup'
00078       >>> from Products.GenericSetup.interfaces import EXTENSION
00079       >>> info['type'] is EXTENSION
00080       True
00081       >>> info['for'] is None
00082       True
00083 
00084     Clean up and make sure the cleanup works::
00085 
00086       >>> from zope.testing.cleanup import cleanUp
00087       >>> cleanUp()
00088       >>> profile_id in _profile_registry._profile_ids
00089       False
00090       >>> profile_id in _profile_registry._profile_info
00091       False
00092     """

Definition at line 376 of file test_zcml.py.

00376 
00377 def test_suite():
00378     suite = unittest.TestSuite()
00379     suite.addTest(doctest.DocTestSuite(optionflags=ELLIPSIS))
00380     suite.addTest(unittest.makeSuite(ImportStepTests))
00381     suite.addTest(unittest.makeSuite(ExportStepTests))
00382     return suite