You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2020/10/12 21:21:40 UTC

[allura] 03/16: [#8376] remove some unnecessary validations

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8378
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 525b3e28a973608335acf2f7bbf86ac9d536274e
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Wed Oct 7 11:25:15 2020 -0400

    [#8376] remove some unnecessary validations
---
 Allura/allura/lib/widgets/forms.py          | 34 ++++++++---------------------
 Allura/allura/tests/functional/test_auth.py | 12 ++++------
 2 files changed, 13 insertions(+), 33 deletions(-)

diff --git a/Allura/allura/lib/widgets/forms.py b/Allura/allura/lib/widgets/forms.py
index 54082ce..507ea41 100644
--- a/Allura/allura/lib/widgets/forms.py
+++ b/Allura/allura/lib/widgets/forms.py
@@ -255,9 +255,7 @@ class PersonalDataForm(ForgeForm):
                 label='Gender',
                 options=[ew.Option(py_value=v, label=v, selected=False)
                          for v in ['Male', 'Female', 'Unknown', 'Other']],
-                validator=formencode.All(
-                    V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other']),
-                    V.UnicodeString(not_empty=True))),
+                validator=V.OneOfValidator(['Male', 'Female', 'Unknown', 'Other'])),
             ew.SingleSelectField(
                 name='country',
                 label='Country of residence',
@@ -450,7 +448,7 @@ class AddSocialNetworkForm(ForgeForm):
             ew.SingleSelectField(
                 name='socialnetwork',
                 label='Social network',
-                validator=V.UnicodeString(not_empty=True),
+                validator=V.OneOfValidator(socialnetworks),
                 options=[ew.Option(py_value=name, label=name)
                          for name in socialnetworks]),
             ew.TextField(
@@ -499,14 +497,10 @@ class AddInactivePeriodForm(ForgeForm):
     class fields(ew_core.NameList):
         startdate = ew.TextField(
             label='Start date',
-            validator=formencode.All(
-                V.DateValidator(),
-                V.UnicodeString(not_empty=True)))
+            validator=V.DateValidator())
         enddate = ew.TextField(
             label='End date',
-            validator=formencode.All(
-                V.DateValidator(),
-                V.UnicodeString(not_empty=True)))
+            validator=V.DateValidator())
 
     @ew_core.core.validator
     def to_python(self, kw, state):
@@ -558,19 +552,13 @@ class AddTimeSlotForm(ForgeForm):
             label='Weekday',
             options=[ew.Option(py_value=wd, label=wd)
                      for wd in weekdays],
-            validator=formencode.All(
-                V.OneOfValidator(weekdays),
-                V.UnicodeString(not_empty=True)))
+            validator=V.OneOfValidator(weekdays))
         starttime = ew.TextField(
             label='Start time',
-            validator=formencode.All(
-                V.TimeValidator(),
-                V.UnicodeString(not_empty=True)))
+            validator=V.TimeValidator())
         endtime = ew.TextField(
             label='End time',
-            validator=formencode.All(
-                V.TimeValidator(),
-                V.UnicodeString(not_empty=True)))
+            validator=V.TimeValidator())
 
     @ew_core.core.validator
     def to_python(self, kw, state):
@@ -700,9 +688,7 @@ class AddUserSkillForm(ForgeForm):
                 ew.Option(py_value="low", label="Low level"),
                 ew.Option(py_value="medium", label="Medium level"),
                 ew.Option(py_value="high", label="Advanced level")],
-            validator=formencode.All(
-                V.OneOfValidator(['low', 'medium', 'high']),
-                V.UnicodeString(not_empty=True)))
+            validator=V.OneOfValidator(['low', 'medium', 'high']))
         comment = ew.TextArea(
             label="Additional comments",
             validator=V.UnicodeString(not_empty=False),
@@ -730,9 +716,7 @@ class SelectSubCategoryForm(ForgeForm):
         self.fields['selected_category'].options = [
             ew.Option(py_value=el.trove_cat_id, label=el.fullname) for el in categories
         ]
-        self.fields['selected_category'].validator = formencode.All(
-            V.OneOfValidator(categories),
-            V.UnicodeString(not_empty=True))
+        self.fields['selected_category'].validator = V.OneOfValidator(categories)
         return super(ForgeForm, self).display(**kw)
 
 
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index c7dd677..0fa9a09 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -1333,10 +1333,8 @@ class TestPreferences(TestController):
                               _session_id=self.app.cookies['_session_id'],
                           ))
         user = M.User.query.get(username='test-admin')
-        timeslot1dict = dict(
-            week_day=weekday, start_time=starttime, end_time=endtime)
-        assert len(
-            user.availability) == 1 and timeslot1dict in user.get_availability_timeslots()
+        timeslot1dict = dict(week_day=weekday, start_time=starttime, end_time=endtime)
+        assert len(user.availability) == 1 and timeslot1dict in user.get_availability_timeslots()
 
         weekday2 = 'Tuesday'
         starttime2 = time(14, 0, 0)
@@ -1351,8 +1349,7 @@ class TestPreferences(TestController):
                               _session_id=self.app.cookies['_session_id'],
                           ))
         user = M.User.query.get(username='test-admin')
-        timeslot2dict = dict(week_day=weekday2,
-                             start_time=starttime2, end_time=endtime2)
+        timeslot2dict = dict(week_day=weekday2, start_time=starttime2, end_time=endtime2)
         assert len(user.availability) == 2
         assert_in(timeslot1dict, user.get_availability_timeslots())
         assert_in(timeslot2dict, user.get_availability_timeslots())
@@ -1378,8 +1375,7 @@ class TestPreferences(TestController):
                           ))
         assert 'Invalid period:' in str(r)
         user = M.User.query.get(username='test-admin')
-        timeslot2dict = dict(week_day=weekday2,
-                             start_time=starttime2, end_time=endtime2)
+        timeslot2dict = dict(week_day=weekday2, start_time=starttime2, end_time=endtime2)
         assert len(user.availability) == 1 and timeslot2dict in user.get_availability_timeslots()
 
     @td.with_user_project('test-admin')