[ckan-changes] commit/ckan: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Fri Sep 9 11:51:05 UTC 2011


2 new changesets in ckan:

http://bitbucket.org/okfn/ckan/changeset/b18ffd87ae73/
changeset:   b18ffd87ae73
branch:      release-v1.4.3
user:        dread
date:        2011-09-08 15:59:39
summary:     [doc][s]: Fix minor mistakes spotted by Max Ludwig.
affected #:  2 files (27 bytes)

--- a/doc/install-from-source.rst	Tue Sep 06 14:59:07 2011 +0100
+++ b/doc/install-from-source.rst	Thu Sep 08 14:59:39 2011 +0100
@@ -167,16 +167,16 @@
 
   ::
 
-      sudo -u postgres createuser -S -D -R -P ckantest
+      sudo -u postgres createuser -S -D -R -P ckanuser
 
   It should prompt you for a new password for the CKAN data in the database.
   It is suggested you enter ``pass`` for the password.
 
-  Now create the database, which we'll call ``ckantest`` (the last argument):
+  Now create the database, which we'll call ``ckantest``:
 
   ::
 
-      sudo -u postgres createdb -O ckantest ckantest
+      sudo -u postgres createdb -O ckanuser ckantest
 
 6. Create a CKAN config file.
 
@@ -201,7 +201,7 @@
 
   ::
   
-      sqlalchemy.url = postgresql://ckantest:pass@localhost/ckantest
+      sqlalchemy.url = postgresql://ckanuser:pass@localhost/ckantest
 
   If you're using a remote host with password authentication rather than SSL authentication, use::
 


--- a/doc/prepare-extensions.rst	Tue Sep 06 14:59:07 2011 +0100
+++ b/doc/prepare-extensions.rst	Thu Sep 08 14:59:39 2011 +0100
@@ -8,7 +8,7 @@
 
 ::
 
-    sudo apt-get install virtualenv pip mercurial
+    sudo apt-get install virtualenv python-pip mercurial
     virtualenv /home/ubuntu/pyenv
     . /home/ubuntu/pyenv/bin/activate
 


http://bitbucket.org/okfn/ckan/changeset/93731cd3b22e/
changeset:   93731cd3b22e
branch:      release-v1.4.3
user:        dread
date:        2011-09-09 13:49:38
summary:     [controllers/user]: #1318 Fix for user registration not logging you in. Added to and tidied up user tests.
affected #:  3 files (2.1 KB)

--- a/ckan/controllers/user.py	Thu Sep 08 14:59:39 2011 +0100
+++ b/ckan/controllers/user.py	Fri Sep 09 12:49:38 2011 +0100
@@ -102,6 +102,9 @@
         return self.new(data, errors, error_summary)
 
     def new(self, data=None, errors=None, error_summary=None):
+        '''GET to display a form for registering a new user.
+           or POST the form data to actually do the user registration.
+        '''
         context = {'model': model, 'session': model.Session,
                    'user': c.user or c.author,
                    'schema': self._new_form_to_db_schema(),
@@ -129,7 +132,6 @@
                 tuplize_dict(parse_params(request.params))))
             context['message'] = data_dict.get('log_message', '')
             user = create.user_create(context, data_dict)
-            h.redirect_to(controller='user', action='read', id=user['name'])
         except NotAuthorized:
             abort(401, _('Unauthorized to create user %s') % '')
         except NotFound, e:
@@ -140,6 +142,11 @@
             errors = e.error_dict
             error_summary = e.error_summary
             return self.new(data_dict, errors, error_summary)
+        # Redirect to a URL picked up by repoze.who which performs the login
+        h.redirect_to('/login_generic?login=%s&password=%s' % (
+            str(data_dict['name']),
+            quote(data_dict['password1'].encode('utf-8'))))
+
 
     def edit(self, id=None, data=None, errors=None, error_summary=None):
         context = {'model': model, 'session': model.Session,
@@ -237,7 +244,7 @@
             response.set_cookie("ckan_display_name", user_dict['display_name'])
             response.set_cookie("ckan_apikey", user_dict['apikey'])
             h.flash_success(_("Welcome back, %s") % user_dict['display_name'])
-            h.redirect_to(controller='user', action='me', id=None)
+            return self.me()
         else:
             h.flash_error('Login failed. Bad username or password.')
             h.redirect_to(controller='user', action='login')


--- a/ckan/templates/user/login.html	Thu Sep 08 14:59:39 2011 +0100
+++ b/ckan/templates/user/login.html	Fri Sep 09 12:49:38 2011 +0100
@@ -34,7 +34,7 @@
   <div py:match="content"><h2>Login</h2>
     
-    <form action="/login_generic" method="post" class="simple-form" id="generic_form">  
+    <form action="/login_generic" method="post" class="simple-form" id="login"><fieldset><!--legend i18n:msg="site_title">Login</legend-->
 


--- a/ckan/tests/functional/test_user.py	Thu Sep 08 14:59:39 2011 +0100
+++ b/ckan/tests/functional/test_user.py	Fri Sep 09 12:49:38 2011 +0100
@@ -125,11 +125,12 @@
         assert 'spamsite2' not in res, res
         assert 'Error: Could not parse About text' in res, res
         
-    def test_user_login(self):
+    def test_user_login_page(self):
         offset = url_for(controller='user', action='login', id=None)
         res = self.app.get(offset, status=200)
         assert 'Login' in res, res
         assert 'Please click your account provider' in res, res
+        assert 'Forgot your password?' in res, res
         assert 'Don\'t have an OpenID' in res, res
 
     def test_logout(self):
@@ -137,19 +138,87 @@
         res2 = res.follow()
         assert 'You have logged out successfully.' in res2, res2
 
-    #def test_user_created_on_login(self):
-    #    username = u'okfntest'
-    #    user = model.User.by_name(username)
-    #    if user:
-    #        user.purge()
-    #        model.Session.commit()
-    #        model.Session.remove()
+    def _get_cookie_headers(self, res):
+        # For a request response, returns the Set-Cookie header values.
+        cookie_headers = []
+        for key, value in res.headers:
+            if key == 'Set-Cookie':
+                cookie_headers.append(value)
+        return cookie_headers
+        
+    def test_login(self):
+        # create test user
+        username = u'testlogin'
+        password = u'letmein'
+        CreateTestData.create_user(name=username,
+                                   password=password)
+        user = model.User.by_name(username)
 
-    #    offset = url_for(controller='user', action='login')
-    #    res = self.app.get(offset, extra_environ=dict(REMOTE_USER='okfntest'))
-    #    user = model.User.by_name(u'okfntest')
-    #    assert user
-    #    assert len(user.apikey) == 36
+        # do the login
+        offset = url_for(controller='user', action='login')
+        res = self.app.get(offset)
+        fv = res.forms['login']
+        fv['login'] = username
+        fv['password'] = password
+        res = fv.submit()
+
+        # check cookies set
+        cookies = self._get_cookie_headers(res)
+        assert cookies
+        
+        # first get redirected to user/logged_in
+        assert_equal(res.status, 302)
+        assert res.header('Location').startswith('http://localhost/user/logged_in')
+
+        # then get redirected to user page
+        res = res.follow()
+        assert_equal(res.status, 302)
+        assert_equal(res.header('Location'), 'http://localhost/user/testlogin')
+        res = res.follow()
+        assert_equal(res.status, 200)
+        assert 'Welcome back, testlogin' in res.body
+        assert 'My Account' in res.body
+        
+        # check user object created
+        user = model.User.by_name(username)
+        assert user
+        assert_equal(user.name, username)
+        assert len(user.apikey) == 36
+
+        # check cookie created
+        assert 'ckan_display_name="testlogin"' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+        assert 'auth_tkt="' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+        assert 'testlogin!userid_type:unicode"' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+
+    def test_login_wrong_password(self):
+        # create test user
+        username = u'testloginwrong'
+        password = u'letmein'
+        CreateTestData.create_user(name=username,
+                                   password=password)
+        user = model.User.by_name(username)
+
+        # do the login
+        offset = url_for(controller='user', action='login')
+        res = self.app.get(offset)
+        fv = res.forms['login']
+        fv['login'] = username
+        fv['password'] = 'wrong_password'
+        res = fv.submit()
+
+        # first get redirected to logged_in
+        assert_equal(res.status, 302)
+        assert res.header('Location').startswith('http://localhost/user/logged_in')
+
+        # then get redirected to login
+        res = res.follow()
+        assert_equal(res.status, 302)
+        assert res.header('Location').startswith('http://localhost/user/login')
+        res = res.follow()
+        assert_equal(res.status, 200)
+        assert 'Login failed. Bad username or password.' in res.body
+        assert 'Login:' in res.body
+
 
     # -----------
     # tests for top links present in every page
@@ -217,16 +286,22 @@
         main_res = self.main_div(res)
         assert fullname in main_res, main_res
 
+        # check saved user object
         user = model.User.by_name(unicode(username))
         assert user
         assert_equal(user.name, username)
         assert_equal(user.fullname, fullname)
         assert user.password
-
+        
         # no revision should be created - User is not revisioned
         rev_id_after_test = model.repo.youngest_revision().id
         assert_equal(rev_id_before_test, rev_id_after_test)
 
+        # check cookies created
+        assert 'ckan_display_name="Test Create"' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+        assert 'auth_tkt="' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+        assert 'testcreate!userid_type:unicode"' in res.request.environ['HTTP_COOKIE'], res.request.environ['HTTP_COOKIE']
+
 
     def test_user_create_unicode(self):
         # create/register user
@@ -537,34 +612,6 @@
         main_res = self.main_div(res)
         assert "Couldn't resolve host" in main_res, main_res
 
-    ############
-    # Disabled
-    ############
-
-    # TODO: 2009-06-27 delete/update these methods (now moving to repoze)
-    def _login_form(self, res):
-        # cannot use for time being due to 'bug' in AuthKit
-        # paste.fixture does not set REMOTE_ADDR which AuthKit requires to do
-        # its stuff (though note comment in code suggesting amendment)
-        # create cookie see authkit/authenticate/cookie.py l. 364 
-            # if self.include_ip:
-            # # Fixes ticket #30
-            # # @@@ should this use environ.get('REMOTE_ADDR','0.0.0.0')?
-            #  remote_addr = environ.get('HTTP_X_FORWARDED_FOR', environ['REMOTE_ADDR'])
-            #  
-            # KeyError: 'REMOTE_ADDR' 
-        # could get round this by adding stuff to environ using paste fixture's
-        # extra_environ, see:
-        # http://pythonpaste.org/webtest/#modifying-the-environment-simulating-authentication
-        assert 'Please Sign In' in res
-        username = u'okfntest'
-        password = u'okfntest'
-        fv = res.forms['user-login']
-        fv['username'] = username
-        fv['password'] = password
-        res = fv.submit()
-        return res
-
     def _login_openid(self, res):
         # this requires a valid account on some openid provider
         # (or for us to stub an open_id provider ...)

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