Skip to content

Commit

Permalink
Merge branch 'dev-v2.6' of github.com:ckan/ckan into dev-v2.6
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 13, 2017
2 parents 28dcc92 + 5caa198 commit b63298e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
5 changes: 0 additions & 5 deletions ckan/model/user.py
Expand Up @@ -55,13 +55,8 @@ def by_email(cls, email):

@classmethod
def get(cls, user_reference):
# double slashes in an openid often get turned into single slashes
# by browsers, so correct that for the openid lookup
corrected_openid_user_ref = cls.DOUBLE_SLASH.sub('://\\1',
user_reference)
query = meta.Session.query(cls).autoflush(False)
query = query.filter(or_(cls.name == user_reference,
cls.openid == corrected_openid_user_ref,
cls.id == user_reference))
return query.first()

Expand Down
20 changes: 11 additions & 9 deletions ckan/tests/legacy/models/test_user.py
@@ -1,7 +1,9 @@
# encoding: utf-8

from nose import SkipTest
from nose.tools import assert_equal


from ckan.tests.legacy import *
import ckan.model as model
from ckan.lib.create_test_data import CreateTestData
Expand All @@ -14,8 +16,8 @@ class TestUser:
def setup_class(self):
CreateTestData.create_user('brian', password='pass',
fullname='Brian', email='brian@brian.com')
CreateTestData.create_user(openid='http://sandra.owndomain.com/',
fullname='Sandra')
CreateTestData.create_user('sandra', password='pass',
fullname='Sandra', email='sandra@sandra.com')

@classmethod
def teardown_class(self):
Expand All @@ -28,7 +30,7 @@ def test_0_basic(self):
assert_equal(out.fullname, 'Brian')
assert_equal(out.email, u'brian@brian.com')

out = model.User.by_openid(u'http://sandra.owndomain.com/')
out = model.User.by_name(u'sandra')
assert_equal(out.fullname, u'Sandra')

def test_1_timestamp_any_existing(self):
Expand All @@ -37,24 +39,25 @@ def test_1_timestamp_any_existing(self):

def test_2_timestamp_new(self):
user = model.User()
openid = u'http://xyz.com'
user.name = openid
name = u'xyz'
user.name = name
model.Session.add(user)
model.repo.commit_and_remove()

out = model.User.by_name(openid)
out = model.User.by_name(name)
assert len(str(out.created)) > 5, out.created

def test_3_get(self):
out = model.User.get(u'brian')
assert out.fullname == u'Brian'

out = model.User.get(u'http://sandra.owndomain.com/')
out = model.User.get(u'sandra')
assert out.fullname == u'Sandra'

def test_4_get_openid_missing_slash(self):
raise SkipTest(u'OpenID is not used anymore')
# browsers seem to lose the double slash
out = model.User.get(u'http:/sandra.owndomain.com/')
out = model.User.get(u'sandra')
assert out
assert out.fullname == u'Sandra'

Expand Down Expand Up @@ -186,4 +189,3 @@ def test_search(self):
'tester' in test_names and
'testsysadmin' in test_names ), \
"Search for test should find tester and testsysadmin (only)"

0 comments on commit b63298e

Please sign in to comment.