Пример #1
0
 def setUp(self):
     self.contentFactory = lambda: []
     self.tabs = [
         widgets.Tab(u'id1', u'Title 1', self.contentFactory),
         widgets.Tab(u'id2', u'Title 2', self.contentFactory),
         widgets.Tab(u'id3', u'Title 3', self.contentFactory)
     ]
     self.tabView = widgets.TabView(self.tabs)
Пример #2
0
 def test_repr(self):
     """
     L{methanal.widgets.TabGroup} has an accurate string representation.
     """
     tabs = [
         widgets.Tab(u'id1', u'Title 1', None),
         widgets.Tab(u'id2', u'Title 2', None)
     ]
     tabGroup = widgets.TabGroup(u'id', u'Title', tabs=tabs)
     self.assertEquals(repr(tabGroup),
                       "<TabGroup id=u'id' title=u'Title' tabs=%r>" % tabs)
Пример #3
0
 def test_athenaSerializable(self):
     """
     Tab groups implement L{nevow.inevow.IAthenaTransportable}.
     """
     tabs = [
         widgets.Tab(u'id1', u'Title 1', None),
         widgets.Tab(u'id2', u'Title 2', None)
     ]
     tabGroup = widgets.TabGroup(u'id', u'Title', tabs=tabs)
     self.assertEquals(
         inevow.IAthenaTransportable(tabGroup).getInitialArguments(),
         [u'id', u'Title', [u'id1', u'id2']])
Пример #4
0
    def test_invalidRemove(self):
        """
        Trying to remove an unmanaged tab results in C{ValueError} being
        raised.
        """
        # Try a new tab.
        self.assertRaises(
            ValueError, self.tabView.removeTabs,
            [widgets.Tab(u'id99', u'Title 1', self.contentFactory)])

        # Try dupe an ID.
        self.assertRaises(
            ValueError, self.tabView.removeTabs,
            [widgets.Tab(u'id1', u'Title 1', self.contentFactory)])
Пример #5
0
    def test_mergeGroups(self):
        """
        L{methanal.widgets.TabGroup.mergeGroups} will merge two
        L{methanal.widgets.TabGroup}s together, preferring the metadata of the
        second specified group.
        """
        tabs = [
            widgets.Tab(u'id1', u'Title 1', None),
            widgets.Tab(u'id2', u'Title 2', None)
        ]
        tabGroup1 = widgets.TabGroup(u'id', u'Title', tabs=tabs)
        tabs = [widgets.Tab(u'id3', u'Title 3', None)]
        tabGroup2 = widgets.TabGroup(u'id', u'Hello', tabs=tabs)

        newGroup = widgets.TabGroup.mergeGroups(tabGroup1, tabGroup2)
        self.assertEquals(newGroup.id, u'id')
        self.assertEquals(newGroup.title, u'Hello')
        self.assertEquals(newGroup.tabs, tabGroup1.tabs + tabGroup2.tabs)
Пример #6
0
 def test_createGroup(self):
     """
     Creating a L{methanal.widgets.TabView} widget initialises
     L{methanal.widgets.TabView._tabsByID}, L{methanal.widgets.TabView.tabs}
     and L{methanal.widgets.TabView._tabGroups} with the values originally
     specified, tab groups are merged in and managed.
     """
     tabGroup = widgets.TabGroup(
         u'group1',
         u'Group',
         tabs=[widgets.Tab(u'id4', u'Title 4', self.contentFactory)])
     tabs = self.tabs + [
         tabGroup,
         widgets.Tab(u'id5', u'Title 5', self.contentFactory)
     ]
     tabView = widgets.TabView(tabs)
     self.assertEquals(tabView.getTabIDs(),
                       [u'id1', u'id2', u'id3', u'id4', u'id5'])
     self.assertEquals(tabView._tabGroups, {u'group1': tabGroup})
Пример #7
0
    def test_updateTabs(self):
        """
        Updating tabs on the server side manages them and invokes methods
        on the client side to insert them.
        """
        self.result = None

        def callRemote(methodName, *a):
            self.result = methodName == '_updateTabsFromServer'

        tab = widgets.Tab(u'id4', u'Title 4', self.contentFactory)
        self.patch(self.tabView, 'callRemote', callRemote)
        self.tabView.updateTabs([tab])
        self.assertTrue(self.result)
        self.assertNotIdentical(self.tabView.getTab(u'id4'), None)
        self.assertIdentical(self.tabView.tabs[-1], tab)

        replacementTab = widgets.Tab(u'id1', u'New title', self.contentFactory)
        oldTab = self.tabView.getTab(u'id1')
        self.tabView.updateTabs([replacementTab])
        self.assertIdentical(self.tabView.getTab(u'id1'), replacementTab)
        self.assertNotIn(oldTab, self.tabView.tabs)
Пример #8
0
    def test_updateGroup(self):
        """
        Updating a group on the server site manages it, and all the tabs it
        contains, and invokes methods on the client side to insert them.
        """
        self.result = None

        def callRemote(methodName, *a):
            self.result = methodName == '_updateTabsFromServer'

        tab = widgets.Tab(u'id4', u'Title 4', self.contentFactory)
        group = widgets.TabGroup(u'group1', u'Group', tabs=[tab])
        self.patch(self.tabView, 'callRemote', callRemote)
        self.tabView.updateGroup(group)
        self.assertTrue(self.result)
        self.assertNotIdentical(self.tabView.getTab(u'id4'), None)
        self.assertNotIdentical(self.tabView.getGroup(u'group1'), None)
        self.assertIdentical(self.tabView.tabs[-1], tab)

        # Update a group, and add a new tab.
        newTab = widgets.Tab(u'id5', u'Title 5', self.contentFactory)
        replacementGroup = widgets.TabGroup(u'group1',
                                            u'New Group',
                                            tabs=[newTab])
        self.tabView.updateGroup(replacementGroup)
        self.assertIdentical(self.tabView.getGroup(u'group1'),
                             replacementGroup)
        self.assertNotIdentical(self.tabView.getTab(u'id5'), None)
        self.assertRaises(errors.InvalidIdentifier, self.tabView.getTab,
                          u'id4')
        self.assertNotIn(tab, self.tabView.tabs)

        # Remove a tab from a group.
        self.tabView.removeTabs([newTab])
        self.assertRaises(errors.InvalidIdentifier, self.tabView.getTab,
                          u'id5')
        self.assertNotIn(newTab, self.tabView.getGroup(u'group1').tabs)