1. paj
  2. tw2.sqla

Commits

pa...@paulj-PC.lab.pentest.co.uk  committed 118eb65

Basic validation tests & a bug fix

  • Participants
  • Parent commits a58c566
  • Branches default

Comments (0)

Files changed (2)

File tests/test_widgets.py

View file
 
 class RadioButtonT(tw2test.WidgetTest):
     widget = tws.DbRadioButtonList
+    declarative = True
     attrs = {'css_class':'something', 'id' : 'something'}
     params = {'checked':None}
     expected = """
     </li>
     </ul>"""
 
+    def test_validation(self):
+        value = self.widget.validate({'something':'1'})
+        assert(value is self.DbTestCls1.query.get(1))
+
     def setup(self):
         self.widget = self.widget(entity=self.DbTestCls1)
         return super(RadioButtonT, self).setup()
 class CheckBoxT(tw2test.WidgetTest):
     widget = tws.DbCheckBoxList
     attrs = {'css_class':'something', 'id' : 'something'}
+    declarative = True
     params = {'checked':None}
     expected = """
     <ul class="something" id="something">
     </li>
     </ul>"""
 
+    def test_validation(self):
+        value = self.widget.validate({'something':'1'})
+        assert(value == [self.DbTestCls1.query.get(1)])
+
     def setup(self):
         self.widget = self.widget(entity=self.DbTestCls1)
         return super(CheckBoxT, self).setup()
 class CheckBoxTableT(tw2test.WidgetTest):
     widget = tws.DbCheckBoxTable
     attrs = {'css_class':'something', 'id' : 'something'}
+    declarative = True
     params = {'checked':None}
     expected = """
     <table class="something" id="something"><tbody>
     </tbody></table>
     """
 
+    def test_validation(self):
+        value = self.widget.validate({'something':'1'})
+        assert(value == [self.DbTestCls1.query.get(1)])
+
     def setup(self):
         self.widget = self.widget(entity=self.DbTestCls1)
         return super(CheckBoxTableT, self).setup()
 class SingleSelectT(tw2test.WidgetTest):
     widget = tws.DbSingleSelectField
     attrs = {'css_class':'something', 'id' : 'something'}
+    declarative = True
     params = {'checked':None}
     expected = """
     <select class="something" name="something" id="something">
     <option value="2">foo2</option>
     </select>"""
 
+    def test_validation(self):
+        value = self.widget.validate({'something':'1'})
+        assert(value is self.DbTestCls1.query.get(1))
+
     def setup(self):
         self.widget = self.widget(entity=self.DbTestCls1)
         return super(SingleSelectT, self).setup()

File tw2/sqla/widgets.py

View file
     entity = twc.Param('SQLAlchemy mapped class to use', request_local=False)
 
     def prepare(self):
+        # avoid hardcoded id
         self.options = [(x.id, unicode(x)) for x in self.entity.query.all()]
         super(DbSelectionField, self).prepare()
 
     @classmethod
     def post_define(cls):
         if getattr(cls, 'entity', None):
-            cls.item_validator = RelatedValidator(entity=cls.entity)
+            cls.validator = RelatedValidator(entity=cls.entity)
 
 class DbCheckBoxTable(DbSelectionField, twf.CheckBoxTable):
     @classmethod
             args = {'id': prop.key}
             if not sum([c.nullable for c in getattr(prop, 'columns', [])]):
                 args['validator'] = twc.Required
-
             widget = widget(**args)
 
-            # TODO - to be determined.  Why is this line necessary?
-            # Without it, some tests fail that shouldn't.
-            widget.display()
-
         return widget