def test_upgrade_step_directive_with_handler(self):
        class Upgrade(UpgradeStep):
            def __call__(self):
                self.install_upgrade_profile()
                portal_actions = self.getToolByName('portal_actions')
                action = portal_actions.portal_tabs.get('test-action')
                assert action, 'The "test-action" was not created on import.'
                action.title = 'Title was changed.'

        self.package.with_profile(
            Builder('genericsetup profile').with_fs_version('2'))
        self.package.with_zcml_include('ftw.upgrade', file='meta.zcml')
        self.package.with_zcml_node('upgrade-step:importProfile',
                                    title='Add and rename test action.',
                                    profile='the.package:default',
                                    source='1',
                                    destination='2',
                                    directory='upgrade-profile/1',
                                    handler='.to2.Upgrade')
        self.package.with_file('to2.py', serialize_callable(Upgrade))
        self.package.with_file('upgrade-profile/1/actions.xml',
                               self.asset('test-action.xml'),
                               makedirs=True)

        with self.package_created():
            self.install_profile('the.package:default', '1')
            self.assertIsNone(self.get_action())
            self.install_profile_upgrades('the.package:default')
            self.assertEqual('Title was changed.', self.get_action().title)
    def test_upgrade_step_directive_with_handler(self):
        class Upgrade(UpgradeStep):
            def __call__(self):
                self.install_upgrade_profile()
                portal_actions = self.getToolByName('portal_actions')
                action = portal_actions.portal_tabs.get('test-action')
                assert action, 'The "test-action" was not created on import.'
                action.title = 'Title was changed.'

        self.package.with_profile(Builder('genericsetup profile').with_fs_version('2'))
        self.package.with_zcml_include('ftw.upgrade', file='meta.zcml')
        self.package.with_zcml_node('upgrade-step:importProfile',
                                    title='Add and rename test action.',
                                    profile='the.package:default',
                                    source='1',
                                    destination='2',
                                    directory='upgrade-profile/1',
                                    handler='.to2.Upgrade')
        self.package.with_file('to2.py', serialize_callable(Upgrade))
        self.package.with_file('upgrade-profile/1/actions.xml',
                               self.asset('test-action.xml'), makedirs=True)

        with self.package_created():
            self.install_profile('the.package:default', '1')
            self.assertIsNone(self.get_action())
            self.install_profile_upgrades('the.package:default')
            self.assertEqual('Title was changed.', self.get_action().title)
Пример #3
0
    def test_builtins_are_not_imported(self):
        class Foo(tuple):
            pass

        self.assertMultiLineEqual('''
class Foo(tuple):
    pass
'''.lstrip(), serialize_callable(Foo))
Пример #4
0
    def calling(self, callable_, *to_import):
        """Make the upgrade step execute the callable passed as argument.
        The callable will be serialized to a string.

        If the callable is a class, superclasses are automatically imported.
        Other globals are not imported and need to be passed to ``calling``
        as additional positional arguments.
        """

        source = serialize_callable(callable_, *to_import)
        return self.with_code(source)
Пример #5
0
    def calling(self, callable_, *to_import):
        """Make the upgrade step execute the callable passed as argument.
        The callable will be serialized to a string.

        If the callable is a class, superclasses are automatically imported.
        Other globals are not imported and need to be passed to ``calling``
        as additional positional arguments.
        """

        source = serialize_callable(callable_, *to_import)
        return self.with_code(source)
Пример #6
0
    def test_serializing_class_imports_superclasses(self):
        class TestSomething(TestCase):
            def test(self):
                assert 'something'

        self.assertMultiLineEqual('''
from unittest2.case import TestCase


class TestSomething(TestCase):
    def test(self):
        assert 'something'
'''.lstrip(), serialize_callable(TestSomething))
Пример #7
0
    def test_globals_to_import_can_be_passed_as_positional_arguments(self):
        def print_docs():
            print parent_namespaces.__docs__
            print serialize_callable.__docs__

        self.assertMultiLineEqual('''
from ftw.builder.utils import parent_namespaces
from ftw.builder.utils import serialize_callable


def print_docs():
    print parent_namespaces.__docs__
    print serialize_callable.__docs__
'''.lstrip(), serialize_callable(print_docs, parent_namespaces, serialize_callable))
Пример #8
0
    def test_serializing_function(self):
        def foo(bar):
            """Prints the argument
            """
            print 'bar is:', bar
            return bar

        self.assertMultiLineEqual('''
def foo(bar):
    """Prints the argument
    """
    print 'bar is:', bar
    return bar
'''.lstrip(), serialize_callable(foo))
Пример #9
0
    def test_callable_is_required(self):
        with self.assertRaises(ValueError) as cm:
            serialize_callable(1)

        self.assertEquals('A callable is required.',
                          str(cm.exception))