Ejemplo n.º 1
0
    def test_file_factory_construction_not_allowed(self):
        container = Container('container')
        container.portal_type = 'containertype'

        child_fti_mock = self.mocker.mock()
        container_fti_mock = self.mocker.mock()
        ctr_mock = self.mocker.mock()
        pt_mock = self.mocker.mock()
        getToolByName_mock = self.mocker.replace(
            'Products.CMFCore.utils.getToolByName')

        self.expect(
            getToolByName_mock(container, 'content_type_registry',
                               None)).result(ctr_mock)
        self.expect(getToolByName_mock(container,
                                       'portal_types')).result(pt_mock)

        self.expect(ctr_mock.findTypeName('test.html', 'text/html',
                                          '<html />')).result('childtype')

        self.expect(pt_mock.getTypeInfo('childtype')).result(child_fti_mock)
        self.expect(pt_mock.getTypeInfo(container)).result(container_fti_mock)

        self.expect(child_fti_mock.product).result(None)

        self.expect(container_fti_mock.allowType('childtype')).result(True)
        self.expect(
            child_fti_mock.isConstructionAllowed(container)).result(False)

        factory = DefaultFileFactory(container)

        self.replay()

        self.assertRaises(Unauthorized, factory, 'test.html', 'text/html',
                          '<html />')
Ejemplo n.º 2
0
    def test_file_factory_content_type_factory_utility(self):
        container_mock = Mock()
        child_fti_mock = Mock()
        child_fti_mock.isConstructionAllowed = Mock(return_value=True)
        child_fti_mock.getId = Mock(return_value='childtype')
        child_fti_mock.product = None
        child_fti_mock.factory = 'childtype-factory'
        container_fti_mock = Mock()
        container_fti_mock.allowType = Mock(return_value=True)
        ctr_mock = Mock()
        ctr_mock.findTypeName = Mock(return_value='childtype')
        pt_mock = Mock()
        pt_mock.getTypeInfo = Mock(
            side_effect=[child_fti_mock, container_fti_mock])
        self.mock_tool(ctr_mock, 'content_type_registry')
        self.mock_tool(pt_mock, 'portal_types')

        def factory(*args, **kwargs):
            return Item(*args, **kwargs)

        self.mock_utility(factory, IFactory, name=u'childtype-factory')

        factory = DefaultFileFactory(container_mock)

        item = factory('test.html', 'text/html', '<html />')

        self.assertEqual('test.html', item.id)
Ejemplo n.º 3
0
    def test_file_factory_finder_cruft(self):
        container = Container('container')
        factory = DefaultFileFactory(container)

        self.assertRaises(Unauthorized, factory, '.DS_Store',
                          'application/octet-stream', 'xxx')
        self.assertRaises(Unauthorized, factory, '._test',
                          'application/octet-stream', 'xxx')
Ejemplo n.º 4
0
    def test_file_factory_factory_utility(self):
        container_mock = self.mocker.mock()
        child_fti_mock = self.mocker.mock()
        container_fti_mock = self.mocker.mock()
        ctr_mock = self.mocker.mock()
        pt_mock = self.mocker.mock()

        result_dummy = self.create_dummy()

        getToolByName_mock = self.mocker.replace(
            'Products.CMFCore.utils.getToolByName'
        )

        self.expect(
            getToolByName_mock(
                container_mock, 'content_type_registry', None
            )
        ).result(ctr_mock)

        self.expect(
            getToolByName_mock(
                container_mock, 'portal_types')).result(pt_mock)

        self.expect(
            ctr_mock.findTypeName('test.html', 'text/html', '<html />')
        ).result('childtype')

        self.expect(
            pt_mock.getTypeInfo('childtype')
        ).result(child_fti_mock)

        self.expect(
            pt_mock.getTypeInfo(container_mock)
        ).result(container_fti_mock)

        self.expect(
            container_fti_mock.allowType('childtype')
        ).result(True)

        self.expect(
            child_fti_mock.isConstructionAllowed(container_mock)
        ).result(True)

        self.expect(child_fti_mock.product).result(None)
        self.expect(child_fti_mock.factory).result('childtype-factory')

        def factory(*args, **kwargs):
            return result_dummy
        self.mock_utility(factory, IFactory, name=u'childtype-factory')

        factory = DefaultFileFactory(container_mock)

        self.replay()

        self.assertEqual(
            result_dummy,
            factory('test.html', 'text/html', '<html />')
        )
Ejemplo n.º 5
0
    def test_file_factory_no_ctr(self):
        container = Container('container')

        from Products.CMFCore.utils import getToolByName
        self.patch_global(getToolByName, return_value=None)

        factory = DefaultFileFactory(container)

        self.assertEqual(None, factory('test.html', 'text/html', '<html />'))
Ejemplo n.º 6
0
    def test_file_factory_no_fti(self):
        container = Container('container')

        ctr_mock = Mock()
        ctr_mock.findTypeName = Mock(return_value=None)
        self.mock_tool(ctr_mock, 'content_type_registry')

        factory = DefaultFileFactory(container)

        self.assertEqual(None, factory('test.html', 'text/html', '<html />'))
Ejemplo n.º 7
0
    def test_file_factory_no_ctr(self):
        container = Container('container')

        getToolByName_mock = self.mocker.replace(
            'Products.CMFCore.utils.getToolByName')
        self.expect(
            getToolByName_mock(container, 'content_type_registry',
                               None)).result(None)

        factory = DefaultFileFactory(container)

        self.replay()

        self.assertEqual(None, factory('test.html', 'text/html', '<html />'))
Ejemplo n.º 8
0
    def test_file_factory_factory_method(self):

        container_mock = self.mocker.mock()
        child_fti_mock = self.mocker.mock()
        ctr_mock = self.mocker.mock()
        pt_mock = self.mocker.mock()

        result_dummy = self.create_dummy()

        getToolByName_mock = self.mocker.replace(
            'Products.CMFCore.utils.getToolByName'
        )

        self.expect(
            getToolByName_mock(
                container_mock, 'content_type_registry', None
            )
        ).result(ctr_mock)
        self.expect(
            getToolByName_mock(
                container_mock, 'portal_types')).result(pt_mock)

        self.expect(
            ctr_mock.findTypeName('test.html', 'text/html', '<html />')
        ).result('childtype')

        self.expect(
            pt_mock.getTypeInfo('childtype')
        ).result(child_fti_mock)

        self.expect(child_fti_mock.product).result('FooProduct')
        self.expect(
            container_mock.invokeFactory('childtype', 'test.html')
        ).result('test-1.html')

        self.expect(container_mock._getOb('test-1.html')).result(result_dummy)
        self.expect(container_mock._delObject('test-1.html'))

        factory = DefaultFileFactory(container_mock)

        self.replay()

        self.assertEqual(
            result_dummy,
            factory('test.html', 'text/html', '<html />')
        )
Ejemplo n.º 9
0
    def test_file_factory_factory_method(self):
        result_dummy = self.create_dummy()
        container_mock = Mock()
        container_mock.invokeFactory = Mock(return_value='test-1.html')
        container_mock._getOb = Mock(return_value=result_dummy)
        container_mock._delObject = Mock()
        child_fti_mock = Mock()
        child_fti_mock.product = 'FooProduct'
        ctr_mock = Mock()
        ctr_mock.findTypeName = Mock(return_value='childtype')
        pt_mock = Mock()
        pt_mock.getTypeInfo = Mock(return_value=child_fti_mock)
        self.mock_tool(ctr_mock, 'content_type_registry')
        self.mock_tool(pt_mock, 'portal_types')

        factory = DefaultFileFactory(container_mock)

        self.assertEqual(result_dummy,
                         factory('test.html', 'text/html', '<html />'))
Ejemplo n.º 10
0
    def test_file_factory_not_allowed(self):
        container = Container('container')
        container.portal_type = 'containertype'

        child_fti_mock = Mock()
        child_fti_mock.product = None
        container_fti_mock = Mock()
        container_fti_mock.allowType = Mock(return_value=False)
        ctr_mock = Mock()
        ctr_mock.findTypeName = Mock(return_value='childtype')
        pt_mock = Mock()
        pt_mock.getTypeInfo = Mock(
            side_effect=[child_fti_mock, container_fti_mock])
        self.mock_tool(ctr_mock, 'content_type_registry')
        self.mock_tool(pt_mock, 'portal_types')

        factory = DefaultFileFactory(container)

        self.assertRaises(Unauthorized, factory, 'test.html', 'text/html',
                          '<html />')