[ckan-changes] commit/ckan: dread: [controllers]: #1033 fix - better error checking for user registration.

Bitbucket commits-noreply at bitbucket.org
Fri Jun 17 11:32:39 UTC 2011


1 new changeset in ckan:

http://bitbucket.org/okfn/ckan/changeset/5c7caca30737/
changeset:   5c7caca30737
branch:      release-v1.4.1
user:        dread
date:        2011-06-17 13:31:41
summary:     [controllers]: #1033 fix - better error checking for user registration.
affected #:  4 files (4.0 KB)

--- a/ckan/controllers/user.py	Thu Jun 16 17:15:36 2011 +0100
+++ b/ckan/controllers/user.py	Fri Jun 17 12:31:41 2011 +0100
@@ -80,9 +80,15 @@
             c.login = request.params.getone('login')
             c.fullname = request.params.getone('fullname')
             c.email = request.params.getone('email')
+            if not c.login:
+                h.flash_error(_("Please enter a login name."))
+                return render("user/register.html")                
             if not model.User.check_name_available(c.login):
                 h.flash_error(_("That username is not available."))
                 return render("user/register.html")
+            if not request.params.getone('password1'):
+                h.flash_error(_("Please enter a password."))
+                return render("user/register.html")                
             try:
                 password = self._get_form_password()
             except ValueError, ve:


--- a/ckan/templates/user/register.html	Thu Jun 16 17:15:36 2011 +0100
+++ b/ckan/templates/user/register.html	Fri Jun 17 12:31:41 2011 +0100
@@ -41,7 +41,7 @@
         <input type="password" name="password2" value="" /><br/></fieldset>
-      ${h.submit('s', _('Sign up'))}
+      ${h.submit('signup', _('Sign up'))}
     </form></div><xi:include href="layout.html" />


--- a/ckan/tests/functional/test_user.py	Thu Jun 16 17:15:36 2011 +0100
+++ b/ckan/tests/functional/test_user.py	Fri Jun 17 12:31:41 2011 +0100
@@ -1,4 +1,5 @@
 from routes import url_for
+from nose.tools import assert_equal
 
 from ckan.tests import search_related, CreateTestData
 from ckan.tests.html_check import HtmlCheckMethods
@@ -47,6 +48,7 @@
         assert 'Revision History' in res, res
 
     def test_user_read_without_id(self):
+        res = self.app.get('/user/logout') # just ensure we're not logged in
         offset = '/user/'
         res = self.app.get(offset, status=302)
 
@@ -169,6 +171,97 @@
         res = self.app.get(offset, extra_environ={'REMOTE_USER': 'okfntest'})
         assert 'Your API key is: %s' % user.apikey in res, res
 
+    def test_user_create(self):
+        # create/register user
+        username = 'testcreate'
+        fullname = u'Test Create'
+        password = u'testpassword'
+        assert not model.User.by_name(unicode(username))
+
+        offset = url_for(controller='user', action='register')
+        res = self.app.get(offset, status=200)
+        main_res = self.main_div(res)
+        assert 'Register' in main_res, main_res
+        fv = res.forms['register_form']
+        fv['login'] = username
+        fv['fullname'] = fullname
+        fv['password1'] = password
+        fv['password2'] = password
+        res = fv.submit('signup')
+        
+        # view user
+        assert res.status == 302, self.main_div(res).encode('utf8')
+        res = res.follow()
+        if res.status == 302:
+            res = res.follow()
+        if res.status == 302:
+            res = res.follow()
+        if res.status == 302:
+            res = res.follow()
+        assert res.status == 200, res
+        main_res = self.main_div(res)
+        assert username in main_res, main_res
+        assert fullname in main_res, main_res
+
+        user = model.User.by_name(unicode(username))
+        assert user
+        assert_equal(user.name, username)
+        assert_equal(user.fullname, fullname)
+        assert user.password
+
+    def test_user_create_no_name(self):
+        # create/register user
+        password = u'testpassword'
+
+        offset = url_for(controller='user', action='register')
+        res = self.app.get(offset, status=200)
+        main_res = self.main_div(res)
+        assert 'Register' in main_res, main_res
+        fv = res.forms['register_form']
+        fv['password1'] = password
+        fv['password2'] = password
+        res = fv.submit('signup')
+        assert res.status == 200, res
+        main_res = self.main_div(res)
+        assert 'Please enter a login name' in main_res, main_res
+
+    def test_user_create_bad_password(self):
+        # create/register user
+        username = 'testcreate2'
+        password = u'a' # too short
+
+        offset = url_for(controller='user', action='register')
+        res = self.app.get(offset, status=200)
+        main_res = self.main_div(res)
+        assert 'Register' in main_res, main_res
+        fv = res.forms['register_form']
+        fv['login'] = username
+        fv['password1'] = password
+        fv['password2'] = password
+        res = fv.submit('signup')
+        assert res.status == 200, res
+        main_res = self.main_div(res)
+        assert 'password must be 4 characters or longer' in main_res, main_res
+        self.check_named_element(main_res, 'input', 'name="login"', 'value="%s"' % username)
+
+    def test_user_create_without_password(self):
+        # create/register user
+        username = 'testcreate3'
+        user = model.User.by_name(unicode(username))
+
+        offset = url_for(controller='user', action='register')
+        res = self.app.get(offset, status=200)
+        main_res = self.main_div(res)
+        assert 'Register' in main_res, main_res
+        fv = res.forms['register_form']
+        fv['login'] = username
+        # no password
+        res = fv.submit('signup')
+        assert res.status == 200, res
+        main_res = self.main_div(res)
+        assert 'Please enter a password' in main_res, main_res
+        self.check_named_element(main_res, 'input', 'name="login"', 'value="%s"' % username)
+
     def test_user_edit(self):
         # create user
         username = 'testedit'


--- a/ckan/tests/html_check.py	Thu Jun 16 17:15:36 2011 +0100
+++ b/ckan/tests/html_check.py	Fri Jun 17 12:31:41 2011 +0100
@@ -41,7 +41,7 @@
         '''Searches in the html and returns True if it can find a particular
         tag and all its subtags & data which contains all the of the
         html_to_find'''
-        named_element_re = re.compile('(<(%(tag)s\w*).*?>.*?</%(tag)s>)' % {'tag':tag_name}) 
+        named_element_re = re.compile('(<(%(tag)s\w*).*?(>.*?</%(tag)s)?>)' % {'tag':tag_name}) 
         html_str = self._get_html_from_res(html)
         self._check_html(named_element_re, html_str.replace('\n', ''), html_to_find)
 
@@ -91,7 +91,11 @@
             if found_all:
                 return # found it
         # didn't find it
-        assert 0, "Couldn't find %s in html. Closest matches were:\n%s" % (', '.join(["'%s'" % html.encode('utf8') for html in html_to_find]), '\n'.join([tag.encode('utf8') for tag in partly_matching_tags]))
+        if partly_matching_tags:
+            assert 0, "Couldn't find %s in html. Closest matches were:\n%s" % (', '.join(["'%s'" % html.encode('utf8') for html in html_to_find]), '\n'.join([tag.encode('utf8') for tag in partly_matching_tags]))
+        else:
+            assert 0, "Couldn't find %s in html. Tags matched were:\n%s" % (', '.join(["'%s'" % html.encode('utf8') for html in html_to_find]), '\n'.join([tag.encode('utf8') for tag in regex_compiled.finditer(html_str)]))
+
 
 
 class Stripper(sgmllib.SGMLParser):

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list