コード例 #1
0
 def test_widget(self):
     from plone.app.z3cform.widget import RelatedItemsWidget
     context = Mock(absolute_url=lambda: 'fake_url')
     context.portal_properties.site_properties\
         .getProperty.return_value = ['SomeType']
     widget = RelatedItemsWidget(self.request)
     widget.context = context
     widget.update()
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'relateditems',
             'pattern_options': {
                 'folderTypes': ['SomeType'],
                 'homeText': u'Home',
                 'searchAllText': u'Entire site',
                 'searchText': u'Search',
                 'separator': ';',
                 'vocabularyUrl': '/@@getVocabulary?name='
                                  'plone.app.vocabularies.Catalog',
             },
         },
         widget._base_args()
     )
コード例 #2
0
    def test_related_items_widget_nav_root(self):
        from plone.app.z3cform.widget import RelatedItemsWidget
        from plone.app.layout.navigation.interfaces import INavigationRoot
        EXPECTED_ROOT_PATH = '/plone'
        EXPECTED_ROOT_URL = 'http://nohost/plone'
        EXPECTED_BASE_PATH = '/plone/subfolder'
        EXPECTED_VOCAB_URL = 'http://nohost/plone/@@getVocabulary?name=plone.app.vocabularies.Catalog'  # noqa

        self.portal.invokeFactory('Folder', 'subfolder')
        subfolder = self.portal['subfolder']
        alsoProvides(subfolder, INavigationRoot)

        widget = RelatedItemsWidget(self.request)
        widget.context = subfolder
        widget.update()
        result = widget._base_args()

        self.assertEqual(
            EXPECTED_ROOT_PATH,
            result['pattern_options']['rootPath']
        )
        self.assertEqual(
            EXPECTED_ROOT_URL,
            result['pattern_options']['rootUrl']
        )
        self.assertEqual(
            EXPECTED_BASE_PATH,
            result['pattern_options']['basePath']
        )
        self.assertEqual(
            EXPECTED_VOCAB_URL,
            result['pattern_options']['vocabularyUrl']
        )
コード例 #3
0
    def test_related_items_widget(self):
        from plone.app.z3cform.widget import RelatedItemsWidget
        EXPECTED_ROOT_PATH = '/plone'
        EXPECTED_ROOT_URL = 'http://nohost/plone'
        EXPECTED_BASE_PATH = '/plone'
        EXPECTED_VOCAB_URL = 'http://nohost/plone/@@getVocabulary?name=plone.app.vocabularies.Catalog'  # noqa

        widget = RelatedItemsWidget(self.request)
        widget.context = self.portal
        widget.update()

        result = widget._base_args()

        self.assertEqual(
            EXPECTED_ROOT_PATH,
            result['pattern_options']['rootPath']
        )
        self.assertEqual(
            EXPECTED_ROOT_URL,
            result['pattern_options']['rootUrl']
        )
        self.assertEqual(
            EXPECTED_BASE_PATH,
            result['pattern_options']['basePath']
        )
        self.assertEqual(
            EXPECTED_VOCAB_URL,
            result['pattern_options']['vocabularyUrl']
        )
コード例 #4
0
 def test_widget(self):
     from plone.app.z3cform.widget import RelatedItemsWidget
     context = Mock(absolute_url=lambda: 'fake_url')
     context.portal_properties.site_properties\
         .getProperty.return_value = ['SomeType']
     widget = RelatedItemsWidget(self.request)
     widget.context = context
     widget.update()
     self.assertEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'relateditems',
             'pattern_options': {
                 'folderTypes': ['SomeType'],
                 'homeText':
                 u'Home',
                 'searchAllText':
                 u'Entire site',
                 'searchText':
                 u'Search',
                 'separator':
                 ';',
                 'vocabularyUrl':
                 '/@@getVocabulary?name='
                 'plone.app.vocabularies.Catalog',
             },
         }, widget._base_args())
コード例 #5
0
ファイル: test_widgets.py プロジェクト: kkdhanesh/NBADEMO
 def test_widget(self):
     from plone.app.z3cform.widget import RelatedItemsWidget
     with patch('plone.app.widgets.utils.getUtility') as mock_method:
         registry = Mock()
         registry.get.return_value = ['SomeType']
         mock_method.return_value = registry
         widget = RelatedItemsWidget(self.request)
         widget.context = Mock(absolute_url=lambda: 'fake_url')
         widget.update()
         self.assertEqual(
             {
                 'name': None,
                 'value': u'',
                 'pattern': 'relateditems',
                 'pattern_options': {
                     'folderTypes': ['SomeType'],
                     'homeText':
                     u'Home',
                     'searchAllText':
                     u'Entire site',
                     'searchText':
                     u'Search',
                     'separator':
                     ';',
                     'vocabularyUrl':
                     '/@@getVocabulary?name='
                     'plone.app.vocabularies.Catalog',
                 },
             }, widget._base_args())
コード例 #6
0
 def test_widget(self):
     from plone.app.z3cform.widget import RelatedItemsWidget
     widget = RelatedItemsWidget(self.request)
     widget.context = Mock(absolute_url=lambda: 'fake_url',
                           getPhysicalPath=lambda: ['', 'site'])
     widget.update()
     self.assertDictEqual(
         {
             'name': None,
             'value': u'',
             'pattern': 'relateditems',
             'pattern_options': {
                 'folderTypes': ['Folder'],
                 'homeText': u'Home',
                 'searchAllText': u'Entire site',
                 'searchText': u'Search',
                 'separator': ';',
                 'vocabularyUrl': 'fake_url/@@getVocabulary?name='
                                  'plone.app.vocabularies.Catalog',
                 'rootPath': '/site',
                 'treeVocabularyUrl':  '/@@getVocabulary?name='
                                       'plone.app.vocabularies.Catalog',
                 'sort_on': 'sortable_title',
                 'sort_order': 'ascending'
             },
         },
         widget._base_args()
     )
コード例 #7
0
    def test_related_items_widget_nav_root(
        self,
        mock_nav_root_ob,
        mock_get_portal
    ):
        from plone.app.z3cform.widget import RelatedItemsWidget
        EXPECTED_PORTAL_ROOT = '', 'site'
        EXPECTED_NAV_ROOT = '', 'site', 'nav'
        EXPECTED_ROOT_PATH = '/site'
        EXPECTED_BASE_PATH = '/site/nav'
        EXPECTED_VOCAB_URL = 'portal_url/@@getVocabulary?name=' \
                             'plone.app.vocabularies.Catalog'
        EXPECTED_TREE_URL = 'portal_url/@@getVocabulary?name=' \
                            'plone.app.vocabularies.Catalog'

        portal = mock.MagicMock(name='portal')
        portal.absolute_url.return_value = 'portal_url'
        portal.getPhysicalPath.return_value = EXPECTED_PORTAL_ROOT
        mock_get_portal.return_value = portal

        navroot = mock.MagicMock(name='navroot')
        navroot.getPhysicalPath.return_value = EXPECTED_NAV_ROOT
        mock_nav_root_ob.return_value = navroot

        widget = RelatedItemsWidget(self.request)
        widget.context = Mock(
            absolute_url=lambda: 'fake_url',
            getPhysicalPath=lambda: ['', 'site', 'nav', 'folder', 'item']
        )
        widget.update()
        result = widget._base_args()
        self.assertEqual(
            EXPECTED_ROOT_PATH,
            result['pattern_options']['rootPath']
        )
        self.assertEqual(
            EXPECTED_BASE_PATH,
            result['pattern_options'].get('basePath', None)
        )
        self.assertEqual(
            EXPECTED_VOCAB_URL,
            result['pattern_options']['vocabularyUrl']
        )
        self.assertEqual(
            EXPECTED_TREE_URL,
            result['pattern_options']['treeVocabularyUrl']
        )
        self.assertDictEqual(
            {
                'name': None,
                'value': u'',
                'pattern': 'relateditems',
                'pattern_options': {
                    'folderTypes': ['Folder'],
                    'homeText': u'Home',
                    'searchAllText': u'Entire site',
                    'searchText': u'Search',
                    'separator': ';',
                    'vocabularyUrl': EXPECTED_VOCAB_URL,
                    'rootPath': EXPECTED_ROOT_PATH,
                    'basePath': EXPECTED_BASE_PATH,
                    'treeVocabularyUrl': EXPECTED_TREE_URL,
                    'sort_on': 'sortable_title',
                    'sort_order': 'ascending'
                },
            },
            result
        )