def test_missingTypeDefaultsToText(self): """ When constructed with an L{IColumn} which returns C{None} from its C{getType} method, L{ScrollingElement} should use the default of C{text} for that column's type. """ class UntypedColumn(object): implements(IColumn) attributeID = 'foo' def sortAttribute(self): return None def getType(self): return None column = UntypedColumn() scroller = ScrollingElement(None, None, None, [DataThunk.a, column], None, webTranslator=object()) attribute, columnList, ascending = scroller.getInitialArguments() self.assertEqual(columnList, [{ u'type': u'integer', u'name': u'a' }, { u'type': u'text', u'name': u'foo' }])
def __init__(self, role, *a, **k): """ Create a L{ShareScrollingElement}. Take all the same arguments as a L{ScrollingElement}, in addition to a L{Role} object that this scrolling view will be restricted to. """ self.role = role ScrollingElement.__init__(self, *a, **k)
def getScrollingElement(self, rowCount): """ Get a L{ScrollingElement} """ s = Store() for x in xrange(rowCount): SampleRowItem(value=(x + 1) * 50, store=s) scrollingElement = ScrollingElement(s, SampleRowItem, None, (SampleRowItem.value, ), None, True, FakeTranslator(s)) scrollingElement.setFragmentParent(self) scrollingElement.docFactory = getLoader(scrollingElement.fragmentName) return scrollingElement
def getScrollingElement(self, rowCount): """ Get a L{ScrollingElement} """ s = Store() for x in xrange(rowCount): SampleRowItem(value=(x + 1) * 50, store=s) scrollingElement = ScrollingElement( s, SampleRowItem, None, (SampleRowItem.value,), None, True, FakeTranslator(s)) scrollingElement.setFragmentParent(self) scrollingElement.docFactory = getLoader( scrollingElement.fragmentName) return scrollingElement
def test_callComparableValue(self): """ L{ScrollingElement} should attempt to call L{IColumn.toComparableValue} to translate input from JavaScript if it is provided by the sort column. """ calledWithValues = [] column = AttributeColumn(DataThunk.a) column.toComparableValue = lambda v: (calledWithValues.append(v), 0)[1] scrollingElement = ScrollingElement( Store(), DataThunk, None, [column], webTranslator=FakeTranslator()) scrollingElement.rowsAfterValue(16, 10) self.assertEqual(calledWithValues, [16]) calledWithValues.pop() scrollingElement.rowsBeforeValue(11, 10) self.assertEqual(calledWithValues, [11])
def test_deprecatedNoToComparableValue(self): """ If L{IColumn.toComparableValue} is I{not} provided by the sort column, then L{ScrollingElement} should notify the developer of a deprecation warning but default to using the value itself. """ class FakeComparator: def __ge__(fc, other): self.shouldBeFakeValue = other __lt__ = __ge__ theFakeComparator = FakeComparator() class FakeOldColumn: implements(IColumn) # but not really; we're missing something! attributeID = 'fake' def sortAttribute(self): return theFakeComparator scrollingElement = ScrollingElement(Store(), DataThunk, None, [FakeOldColumn()], webTranslator=FakeTranslator()) # Now, completely hamstring the implementation; we are interested in # something very specific here, so we just want to capture one value. # (Passing it further on, for example to Axiom, would not result in # testing anything useful, since it is the individual column's # responsibility to yield useful values here anyway, and this test is # explicitly for the case where it's *not* doing that, but happened to # work before anyway!) scrollingElement.inequalityQuery = lambda a, b, c: None scrollingElement.constructRows = lambda nothing: () for lenientMethod in [ scrollingElement.rowsBeforeValue, scrollingElement.rowsAfterValue ]: fakeValue = object() self.assertWarns( DeprecationWarning, "IColumn implementor %s.FakeOldColumn does not " "implement method toComparableValue. This is " "required since Mantissa 0.6.6." % (__name__, ), __file__, lenientMethod, fakeValue, 10) self.assertIdentical(fakeValue, self.shouldBeFakeValue)
def scroller(): """ Create a scrolling element with a large number of rows for use in an interactive demonstration. """ aStore = Store() populate(aStore) se = ScrollingElement(aStore, Sample, None, [Sample.quantity, Sample.date, Sample.title, SampleColorWidgetColumn()], webTranslator=FakeTranslator(aStore), defaultSortAscending=False) se.docFactory = getLoader(se.fragmentName) return se
def scroller(): """ Create a scrolling element with a large number of rows for use in an interactive demonstration. """ aStore = Store() populate(aStore) se = ScrollingElement(aStore, Sample, None, [ Sample.quantity, Sample.date, Sample.title, SampleColorWidgetColumn() ], webTranslator=FakeTranslator(aStore), defaultSortAscending=False) se.docFactory = getLoader(se.fragmentName) return se
def test_initialWidgetArguments(self): """ Verify that the arguments the client widget expects: the name of the current sort column, a list of the available data columns, and the sort order. """ s = Store() testElement = ScrollingElement(s, DataThunk, None, [DataThunk.a, DataThunk.c], DataThunk.a, True, FakeTranslator()) self.assertEqual(testElement.getInitialArguments(), [u"a", [{u"name": u"a", u"type": u"integer"}, {u"name": u"c", u"type": u"text"}], True])
def test_initialWidgetArguments(self): """ Verify that the arguments the client widget expects: the name of the current sort column, a list of the available data columns, and the sort order. """ s = Store() testElement = ScrollingElement(s, DataThunk, None, [DataThunk.a, DataThunk.c], DataThunk.a, True, FakeTranslator()) self.assertEqual(testElement.getInitialArguments(), [ u"a", [{ u"name": u"a", u"type": u"integer" }, { u"name": u"c", u"type": u"text" }], True ])
def test_deprecatedNoToComparableValue(self): """ If L{IColumn.toComparableValue} is I{not} provided by the sort column, then L{ScrollingElement} should notify the developer of a deprecation warning but default to using the value itself. """ class FakeComparator: def __ge__(fc, other): self.shouldBeFakeValue = other __lt__ = __ge__ theFakeComparator = FakeComparator() class FakeOldColumn: implements(IColumn) # but not really; we're missing something! attributeID = 'fake' def sortAttribute(self): return theFakeComparator scrollingElement = ScrollingElement( Store(), DataThunk, None, [FakeOldColumn()], webTranslator=FakeTranslator()) # Now, completely hamstring the implementation; we are interested in # something very specific here, so we just want to capture one value. # (Passing it further on, for example to Axiom, would not result in # testing anything useful, since it is the individual column's # responsibility to yield useful values here anyway, and this test is # explicitly for the case where it's *not* doing that, but happened to # work before anyway!) scrollingElement.inequalityQuery = lambda a, b, c: None scrollingElement.constructRows = lambda nothing : () for lenientMethod in [scrollingElement.rowsBeforeValue, scrollingElement.rowsAfterValue]: fakeValue = object() self.assertWarns(DeprecationWarning, "IColumn implementor %s.FakeOldColumn does not " "implement method toComparableValue. This is " "required since Mantissa 0.6.6." % (__name__,), __file__, lenientMethod, fakeValue, 10) self.assertIdentical(fakeValue, self.shouldBeFakeValue)
def test_missingTypeDefaultsToText(self): """ When constructed with an L{IColumn} which returns C{None} from its C{getType} method, L{ScrollingElement} should use the default of C{text} for that column's type. """ class UntypedColumn(object): implements(IColumn) attributeID = 'foo' def sortAttribute(self): return None def getType(self): return None column = UntypedColumn() scroller = ScrollingElement( None, None, None, [DataThunk.a, column], None, webTranslator=object()) attribute, columnList, ascending = scroller.getInitialArguments() self.assertEqual( columnList, [{u'type': u'integer', u'name': u'a'}, {u'type': u'text', u'name': u'foo'}])
def test_callComparableValue(self): """ L{ScrollingElement} should attempt to call L{IColumn.toComparableValue} to translate input from JavaScript if it is provided by the sort column. """ calledWithValues = [] column = AttributeColumn(DataThunk.a) column.toComparableValue = lambda v: (calledWithValues.append(v), 0)[1] scrollingElement = ScrollingElement(Store(), DataThunk, None, [column], webTranslator=FakeTranslator()) scrollingElement.rowsAfterValue(16, 10) self.assertEqual(calledWithValues, [16]) calledWithValues.pop() scrollingElement.rowsBeforeValue(11, 10) self.assertEqual(calledWithValues, [11])
def makeScrollingElement(): return ScrollingElement(Store(), DataThunk, None, [DataThunk.a], DataThunk.a, True)