[PATCH 6/6] Added a validation test for the GUI group list

Vratislav Podzimek vpodzime at redhat.com
Wed Aug 21 09:11:49 UTC 2013


On Tue, 2013-08-20 at 15:38 -0400, David Shea wrote:
> ---
>  pyanaconda/constants.py                      | 16 ++++++
>  pyanaconda/ui/gui/__init__.py                | 77 ++++++++++++++++++++++++++++
>  pyanaconda/ui/gui/spokes/advanced_user.glade | 24 ++++++---
>  pyanaconda/ui/gui/spokes/user.py             | 32 ++++++++++--
>  tests/regex_tests/groupparse_test.py         | 69 +++++++++++++++++++++++++
>  5 files changed, 208 insertions(+), 10 deletions(-)
>  create mode 100755 tests/regex_tests/groupparse_test.py
> 
> diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
> index 086ece8..d47590e 100644
> --- a/pyanaconda/constants.py
> +++ b/pyanaconda/constants.py
> @@ -173,5 +173,21 @@ GROUPNAME_VALID = USERNAME_VALID
>  # before and after the commas. The empty string is allowed.
>  GROUPLIST_SIMPLE_VALID = re.compile(r'^\s*(' + _USERNAME_BASE + r'(\s*,\s*' + _USERNAME_BASE + r')*)?\s*$')
>  
> +# Parse the <gr-name> (<gid>) strings in the group list.
> +#
> +# The name match is non-greedy so that it doesn't match the whitespace betweeen
> +# the name and ID.
> +#
> +# There's some non-capturing groups ("clusters" in the perlre parlance) thrown
> +# in there, and, haha, wow, that's confusing to look at. There are two groups
> +# that actually end up in the match object, and they're named to try to make
> +# it a little easier: the first is "name", and the second is "gid".
> +#
> +# EVERY STRING IS MATCHED. This expression cannot be used for validation.
> +# If there is no GID, or the GID contains non-digits, everything except
> +# leading or trailing whitespace ends up in the name group. The result needs to
> +# be validated with GROUPNAME_VALID.
> +GROUPLIST_FANCY_PARSE = re.compile(r'^(?:\s*)(?P<name>.*?)\s*(?:\((?P<gid>\d+)\))?(?:\s*)$')
> +
>  # Proxy parsing
>  PROXY_URL_PARSE = re.compile("([A-Za-z]+://)?(([A-Za-z0-9]+)(:[^:@]+)?@)?([^:/]+)(:[0-9]+)?(/.*)?")
> diff --git a/pyanaconda/ui/gui/__init__.py b/pyanaconda/ui/gui/__init__.py
> index f408257..6174409 100644
> --- a/pyanaconda/ui/gui/__init__.py
> +++ b/pyanaconda/ui/gui/__init__.py
> @@ -343,6 +343,83 @@ class GUIObject(common.UIObject):
>          """All failed input checks"""
>          return (c for c in self._check_list if c.check_status)
>  
> +class GUIDialog(GUIObject):
> +    """This is an abstract for creating dialog windows. It implements the
> +       update_check interface to display an error message when an input
> +       validation fails.
> +
> +       GUIDialog does not define where errors are displayed, so classes
> +       that derive from GUIDialog must define error labels and include them
> +       as a parameter to add_check. More than one check can use the same
> +       label: the message from the first failed check will update the label.
> +    """
Do we really need a special class for that? Especially if it overrides
parent class' methods in a potentially problematic way? I'd suggest
making add_check more general by taking a check function and set_error
function, that would make sure the errors is displayed to the user. That
would also allow to remove the updateCheck method of the GUIObject.

> diff --git a/tests/regex_tests/groupparse_test.py b/tests/regex_tests/groupparse_test.py
> new file mode 100755
> index 0000000..20cccc5
> --- /dev/null
> +++ b/tests/regex_tests/groupparse_test.py
> @@ -0,0 +1,69 @@
> +#!/usr/bin/python
> +#
> +# Copyright (C) 2010-2013  Red Hat, Inc.
> +#
> +# This copyrighted material is made available to anyone wishing to use,
> +# modify, copy, or redistribute it subject to the terms and conditions of
> +# the GNU General Public License v.2, or (at your option) any later version.
> +# This program is distributed in the hope that it will be useful, but WITHOUT
> +# ANY WARRANTY expressed or implied, including the implied warranties of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
> +# Public License for more details.  You should have received a copy of the
> +# GNU General Public License along with this program; if not, write to the
> +# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
> +# 02110-1301, USA.  Any Red Hat trademarks that are incorporated in the
> +# source code or documentation are not subject to the GNU General Public
> +# License and may only be used or replicated with the express permission of
> +# Red Hat, Inc.
> +#
> +# Red Hat Author(s): David Shea <dshea at redhat.com>
> +#
> +import unittest
> +
> +from pyanaconda.constants import GROUPLIST_FANCY_PARSE
> +
> +class GroupParseTestCase(unittest.TestCase):
> +    def testGroupList(self):
> +        """Test a list of possible group-name (GID) values with the group
> +           parsing regex. 
> +           
> +           Tests are in the form of: (string, match.groups() tuple)
> +        """
> +
> +
> +        tests = [("group", ("group", None)),
> +                 ("group  ", ("group", None)),
> +                 ("  group", ("group", None)),
> +                 ("  group  ", ("group", None)),
> +                 ("group (1000)", ("group", "1000")),
> +                 ("group (1000)  ", ("group", "1000")),
> +                 ("  group (1000)", ("group", "1000")),
> +                 ("  group (1000)  ", ("group", "1000")),
> +                 ("group(1000)", ("group", "1000")),
> +                 ("(1000)", ("", "1000")),
> +                 ("  (1000)", ("", "1000")),
> +                 ("(1000)  ", ("", "1000")),
> +                 ("  (1000)  ", ("", "1000")),
> +                 ("group (1000", ("group (1000", None)),
> +                 ("group (abcd)", ("group (abcd)", None)),
> +                 ("", ("", None)),
> +                 ]
> +
> +        got_error = False
> +        for group, result in tests:
> +            try:
> +                self.assertEqual(GROUPLIST_FANCY_PARSE.match(group).groups(), result)
> +            except AssertionError as error:
> +                got_error = True
> +                print(error)
> +
> +        if got_error:
> +            self.fail()
> +
> +def suite():
> +    return unittest.TestLoader().loadTestsFromTestCase(ProxyRegexTestCase)
> +
> +
> +if __name__ == "__main__":
> +    unittest.main()
> +
Again the same comment with a test stucture.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list