Back to index

plone3  3.1.7
test_profile_metadata.py
Go to the documentation of this file.
00001 ##############################################################################
00002 #
00003 # Copyright (c) 2007 Zope Corporation and Contributors. All Rights Reserved.
00004 #
00005 # This software is subject to the provisions of the Zope Public License,
00006 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
00007 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
00008 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00009 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
00010 # FOR A PARTICULAR PURPOSE.
00011 #
00012 ##############################################################################
00013 """ Unit tests for ProfileMetadata.
00014 
00015 $Id: test_profile_metadata.py 82201 2007-12-08 19:13:49Z tseaver $
00016 """
00017 import unittest
00018 import os
00019 
00020 from Testing.ZopeTestCase import ZopeTestCase
00021 from Testing.ZopeTestCase import installProduct
00022 
00023 from Products.GenericSetup import profile_registry
00024 from Products.GenericSetup.metadata import ProfileMetadata
00025 
00026 desc = 'DESCRIPTION TEXT'
00027 version = 'VERSION'
00028 dep1 = 'DEPENDENCY 1'
00029 dep2 = 'DEPENDENCY 2'
00030 
00031 _METADATA_XML = """<?xml version="1.0"?>
00032 <metadata>
00033   <description>%s</description>
00034   <version>%s</version>
00035   <dependencies>
00036     <dependency>%s</dependency>
00037     <dependency>%s</dependency>
00038   </dependencies>
00039 </metadata>
00040 """ % (desc, version, dep1, dep2)
00041 
00042 _METADATA_MAP = {
00043     'description': desc,
00044     'version': version,
00045     'dependencies': (dep1, dep2),
00046     }
00047 
00048 class ProfileMetadataTests( ZopeTestCase ):
00049 
00050     installProduct('GenericSetup')
00051 
00052     def test_parseXML(self):
00053         metadata = ProfileMetadata( '' )
00054         parsed = metadata.parseXML( _METADATA_XML )
00055         self.assertEqual(parsed, _METADATA_MAP)
00056 
00057     def test_versionFromProduct(self):
00058         import warnings
00059         warnings.filterwarnings('ignore')
00060         try:
00061             profile_id = 'dummy_profile'
00062             product_name = 'GenericSetup'
00063             directory = os.path.split(__file__)[0]
00064             path = os.path.join(directory, 'default_profile')
00065             profile_registry.registerProfile( profile_id,
00066                                               'Dummy Profile',
00067                                               'This is a dummy profile',
00068                                               path,
00069                                               product=product_name)
00070             profile_info = profile_registry.getProfileInfo(
00071                                 '%s:%s' % (product_name, profile_id))
00072             product = getattr(self.app.Control_Panel.Products, product_name)
00073             self.assertEqual(profile_info['version'], product.version)
00074         finally:
00075             warnings.resetwarnings()
00076 
00077     def test_relativePath(self):
00078         profile_id = 'dummy_profile2'
00079         product_name = 'GenericSetup'
00080         profile_registry.registerProfile(
00081             profile_id, 'Dummy Profile', 'This is a dummy profile',
00082             'tests/metadata_profile', product=product_name)
00083         profile_info = profile_registry.getProfileInfo(
00084             '%s:%s' % (product_name, profile_id))
00085         self.assertEqual(profile_info['description'],
00086                          'Description from metadata')
00087 
00088 def test_suite():
00089     return unittest.TestSuite((
00090         unittest.makeSuite( ProfileMetadataTests ),
00091         ))
00092 
00093 if __name__ == '__main__':
00094     from Products.GenericSetup.testing import run
00095     run(test_suite())