def test_view_request_value(self): search = self.root.search field = criterion.FullTextCriterionField() request = TestRequest(form={"fulltext": "Dancing fever"}) data = queryMultiAdapter((field, search), ICriterionData) view = queryMultiAdapter((field, search, request), ICriterionView) self.assertTrue(verifyObject(ICriterionView, view)) self.assertEqual(view.getWidgetValue(), u"Dancing fever") self.assertEqual(view.getIndexId(), "fulltext") self.assertEqual(view.getIndexValue(), u"Dancing fever") self.assertEqual(data.getValue(), None) view.saveWidgetValue() self.assertEqual(data.getValue(), u"Dancing fever")
def test_view(self): search = self.root.search field = criterion.FullTextCriterionField() request = TestRequest() data = queryMultiAdapter((field, search), ICriterionData) view = queryMultiAdapter((field, search, request), ICriterionView) self.assertTrue(verifyObject(ICriterionView, view)) self.assertEqual(view.canBeShown(), True) self.assertEqual(view.getWidgetValue(), None) self.assertEqual(view.getIndexId(), "fulltext") self.assertEqual(view.getIndexValue(), None) self.assertEqual(data.getValue(), None) view.saveWidgetValue() self.assertEqual(data.getValue(), None)
def test_data(self): search = self.root.search field = criterion.FullTextCriterionField() data = queryMultiAdapter((field, search), ICriterionData) self.assertTrue(verifyObject(ICriterionData, data)) data.setValue(u"I will go into the woods") self.assertEqual(data.getValue(), u"I will go into the woods") # XXX Should I test that here ? self.assertTrue("fulltext" in search.searchValues) self.assertEqual( search.searchValues["fulltext"], u"I will go into the woods") data.setValue(None) self.assertEqual(data.getValue(), None) self.assertFalse("fulltext" in search.searchValues)
def test_view_default_value(self): search = self.root.search field = criterion.FullTextCriterionField() request = TestRequest(form={"fulltext": ""}) data = queryMultiAdapter((field, search), ICriterionData) data.setValue(u"Disco night") view = queryMultiAdapter((field, search, request), ICriterionView) self.assertTrue(verifyObject(ICriterionView, view)) # This fallback on stored value self.assertEqual(view.getWidgetValue(), u"Disco night") self.assertEqual(view.getIndexId(), "fulltext") self.assertEqual(view.getIndexValue(), u"Disco night") self.assertEqual(data.getValue(), u"Disco night") view.saveWidgetValue() # We didn't have any value in the request so it got deleted self.assertEqual(data.getValue(), None)
def test_criterion(self): field = criterion.FullTextCriterionField() self.assertTrue(verifyObject(ICriterionField, field)) self.assertEqual(field.getName(), "fulltext") self.assertEqual(field.getIndexId(), "fulltext")