Skip to content

Commit

Permalink
Merge branch 'master' into enhancement-2244-clean-up-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Mar 20, 2012
2 parents 7535aef + cced74c commit a9385df
Show file tree
Hide file tree
Showing 24 changed files with 620 additions and 777 deletions.
12 changes: 10 additions & 2 deletions ckan/controllers/template.py
@@ -1,4 +1,5 @@
from ckan.lib.base import *
from genshi.template.loader import TemplateNotFound

class TemplateController(BaseController):

Expand Down Expand Up @@ -26,5 +27,12 @@ def view(self, url):
"""
try:
return render(url)
except:
abort(404)
except TemplateNotFound:
if url.endswith('.html'):
abort(404)
url += '.html'
try:
return render(url)
except TemplateNotFound:
abort(404)

2 changes: 1 addition & 1 deletion ckan/lib/dictization/model_dictize.py
Expand Up @@ -294,7 +294,7 @@ def user_list_dictize(obj_list, context,
return sorted(result_list, key=sort_key, reverse=reverse)

def member_dictize(member, context):
return table_dictize(member, context)
return d.table_dictize(member, context)

def user_dictize(user, context):

Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/admin/index.html
Expand Up @@ -16,6 +16,8 @@ <h3>Current Sysadmins</h3>
${h.linked_user(user)}
</li>
</ul>

<span class="insert-comment-recent"></span>
</div>

<xi:include href="layout.html" />
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/package/read.html
Expand Up @@ -89,6 +89,8 @@ <h3>Related Datasets</h3>
</py:if>

<xi:include href="read_core.html" />

<span class="insert-comment-thread"></span>
</div>

<py:def function="optional_head">
Expand Down
2 changes: 2 additions & 0 deletions ckan/templates/package/resource_read.html
Expand Up @@ -164,6 +164,8 @@ <h3>Additional Information</h3>
</tbody>
</table>
</div>

<span class="insert-comment-thread"></span>
</div>

<py:def function="optional_footer">
Expand Down
67 changes: 53 additions & 14 deletions ckan/tests/functional/api/model/test_vocabulary.py
Expand Up @@ -2,27 +2,55 @@
from pylons.test import pylonsapp
import paste.fixture
from ckan.lib.helpers import json
import ckan.lib.dictization.model_dictize as model_dictize
import sqlalchemy
from nose.tools import raises, assert_raises

class TestVocabulary(object):

def setup(self):
@classmethod
def setup_class(self):
self.app = paste.fixture.TestApp(pylonsapp)
ckan.tests.CreateTestData.create()
self.sysadmin_user = ckan.model.User.get('testsysadmin')
self.normal_user = ckan.model.User.get('annafan')
# Make a couple of test vocabularies needed later.
self.genre_vocab = self._create_vocabulary(vocab_name="Genre",
user=self.sysadmin_user)
self.timeperiod_vocab = self._create_vocabulary(
vocab_name="Time Period", user=self.sysadmin_user)
self.composers_vocab = self._create_vocabulary(vocab_name="Composers",
user=self.sysadmin_user)

def teardown(self):
@classmethod
def teardown_class(self):
ckan.model.repo.rebuild_db()

def setup(self):
self.clean_vocab()
model = ckan.model
context = {'model': model}

genre = model.Vocabulary("Genre")
time_period = ckan.model.Vocabulary("Time Period")
composers = ckan.model.Vocabulary("Composers")
model.Session.add_all([genre, time_period, composers])

self.genre_vocab = model_dictize.vocabulary_dictize(genre, context)
self.timeperiod_vocab = model_dictize.vocabulary_dictize(time_period, context)
self.composers_vocab = model_dictize.vocabulary_dictize(composers, context)
ckan.model.Session.commit()

self.sysadmin_user = ckan.model.User.get('admin')
self.normal_user = ckan.model.User.get('normal')
if not self.sysadmin_user:
normal_user = ckan.model.User(name=u'normal', password=u'annafan')
sysadmin_user = ckan.model.User(name=u'admin', password=u'testsysadmin')
ckan.model.Session.add(normal_user)
ckan.model.Session.add(sysadmin_user)
ckan.model.add_user_to_role(sysadmin_user, ckan.model.Role.ADMIN, ckan.model.System())
ckan.model.Session.commit()
self.sysadmin_user = ckan.model.User.get('admin')
self.normal_user = ckan.model.User.get('normal')

def clean_vocab(self):
ckan.model.Session.execute('delete from package_tag_revision')
ckan.model.Session.execute('delete from package_tag')
ckan.model.Session.execute('delete from tag')
ckan.model.Session.execute('delete from vocabulary')
ckan.model.Session.commit()

@classmethod
def _post(self, url, params=None, extra_environ=None):
if params is None:
params = {}
Expand All @@ -32,6 +60,7 @@ def _post(self, url, params=None, extra_environ=None):
assert not response.errors
return response.json

@classmethod
def _create_vocabulary(self, vocab_name=None, user=None):
# Create a new vocabulary.
params = {'name': vocab_name}
Expand Down Expand Up @@ -506,6 +535,8 @@ def test_vocabulary_update_bad_tags(self):
'''Test updating vocabularies with invalid tags.
'''
apikey = str(self.sysadmin_user.apikey)

for tags in (
[{'id': 'xxx'}, {'name': 'foo'}],
[{'name': 'foo'}, {'name': None}],
Expand All @@ -517,8 +548,7 @@ def test_vocabulary_update_bad_tags(self):
params = {'id': self.genre_vocab['name'], 'tags': tags}
response = self.app.post('/api/action/vocabulary_update',
params=json.dumps(params),
extra_environ = {'Authorization':
str(self.sysadmin_user.apikey)},
extra_environ = {'Authorization': apikey},
status=409)
assert response.json['success'] == False
assert response.json['error']['tags']
Expand Down Expand Up @@ -773,6 +803,9 @@ def test_add_vocab_tag_to_dataset(self):
'''Test that a tag belonging to a vocab can be added to a dataset,
retrieved from the dataset, and then removed from the dataset.'''

ckan.model.repo.rebuild_db()
self.setup()
ckan.tests.CreateTestData.create()
# First add a tag to the vocab.
vocab = self.genre_vocab
tag = self._create_tag(self.sysadmin_user, 'noise', vocab)
Expand Down Expand Up @@ -815,6 +848,9 @@ def test_add_vocab_tag_to_dataset(self):
def test_delete_tag_from_vocab(self):
'''Test that a tag can be deleted from a vocab.'''

ckan.model.repo.rebuild_db()
self.setup()
ckan.tests.CreateTestData.create()
vocab = self.genre_vocab

# First add some tags to the vocab.
Expand Down Expand Up @@ -877,6 +913,9 @@ def test_delete_free_tag(self):
automatically removed from datasets.
'''
ckan.model.repo.rebuild_db()
self.setup()
ckan.tests.CreateTestData.create()
# Get a package from the API.
package = (self._post('/api/action/package_show',
{'id': self._post('/api/action/package_list')['result'][0]})
Expand Down
4 changes: 2 additions & 2 deletions ckan/tests/functional/test_admin.py
Expand Up @@ -9,7 +9,7 @@ def setup_class(cls):

@classmethod
def teardown_class(self):
CreateTestData.delete()
model.repo.rebuild_db()

#test that only sysadmins can access the /ckan-admin page
def test_index(self):
Expand Down Expand Up @@ -46,7 +46,7 @@ def setup_class(cls):

@classmethod
def teardown_class(self):
CreateTestData.delete()
model.repo.rebuild_db()

def test_role_table(self):

Expand Down
5 changes: 0 additions & 5 deletions ckan/tests/functional/test_home.py
Expand Up @@ -41,11 +41,6 @@ def test_template_head_end(self):
res = self.app.get(offset)
assert 'ckan.template_head_end = <link rel="stylesheet" href="TEST_TEMPLATE_HEAD_END.css" type="text/css"> '

def test_template_head_end(self):
offset = url_for('home')
res = self.app.get(offset)
assert 'ckan.template_head_end = <link rel="stylesheet" href="TEST_TEMPLATE_HEAD_END.css" type="text/css"> '

def test_template_footer_end(self):
offset = url_for('home')
res = self.app.get(offset)
Expand Down
10 changes: 9 additions & 1 deletion ckan/tests/functional/test_user.py
@@ -1,5 +1,7 @@
from routes import url_for
from nose.tools import assert_equal
from pylons import config
import hashlib

from pprint import pprint
from ckan.tests import search_related, CreateTestData
Expand All @@ -12,7 +14,13 @@

class TestUserController(FunctionalTestCase, HtmlCheckMethods, PylonsTestCase, SmtpServerHarness):
@classmethod
def setup_class(self):
def setup_class(cls):
smtp_server = config.get('test_smtp_server')
if smtp_server:
host, port = smtp_server.split(':')
port = int(port) + int(str(hashlib.md5(cls.__name__).hexdigest())[0], 16)
config['test_smtp_server'] = '%s:%s' % (host, port)

PylonsTestCase.setup_class()
SmtpServerHarness.setup_class()
CreateTestData.create()
Expand Down
6 changes: 6 additions & 0 deletions ckan/tests/lib/test_mailer.py
Expand Up @@ -2,6 +2,7 @@
from nose.tools import assert_equal, assert_raises
from pylons import config
from email.mime.text import MIMEText
import hashlib

from ckan import model
from ckan.tests.pylons_controller import PylonsTestCase
Expand All @@ -13,6 +14,11 @@
class TestMailer(SmtpServerHarness, PylonsTestCase):
@classmethod
def setup_class(cls):
smtp_server = config.get('test_smtp_server')
if smtp_server:
host, port = smtp_server.split(':')
port = int(port) + int(str(hashlib.md5(cls.__name__).hexdigest())[0], 16)
config['test_smtp_server'] = '%s:%s' % (host, port)
CreateTestData.create_user(name='bob', email='bob@bob.net')
CreateTestData.create_user(name='mary') #NB No email addr provided
SmtpServerHarness.setup_class()
Expand Down
6 changes: 6 additions & 0 deletions ckan/tests/misc/test_mock_mail_server.py
Expand Up @@ -2,6 +2,7 @@
from nose.tools import assert_equal
from pylons import config
from email.mime.text import MIMEText
import hashlib

from ckan.tests.pylons_controller import PylonsTestCase
from ckan.tests.mock_mail_server import SmtpServerHarness
Expand All @@ -10,6 +11,11 @@
class TestMockMailServer(SmtpServerHarness, PylonsTestCase):
@classmethod
def setup_class(cls):
smtp_server = config.get('test_smtp_server')
if smtp_server:
host, port = smtp_server.split(':')
port = int(port) + int(str(hashlib.md5(cls.__name__).hexdigest())[0], 16)
config['test_smtp_server'] = '%s:%s' % (host, port)
SmtpServerHarness.setup_class()
PylonsTestCase.setup_class()

Expand Down
2 changes: 2 additions & 0 deletions ckan/tests/mock_mail_server.py
Expand Up @@ -2,6 +2,7 @@
import asyncore
import socket
from smtpd import SMTPServer
import hashlib

from pylons import config

Expand Down Expand Up @@ -67,6 +68,7 @@ def setup_class(cls):
host, port = smtp_server.split(':')
else:
host, port = smtp_server, 25
cls.port = port
cls.smtp_thread = MockSmtpServerThread(host, int(port))
cls.smtp_thread.start()

Expand Down
3 changes: 3 additions & 0 deletions ckan/tests/models/test_package.py
Expand Up @@ -479,6 +479,9 @@ class TestPackagePurge:
@classmethod
def setup_class(self):
CreateTestData.create()
@classmethod
def teardown_class(self):
model.repo.rebuild_db()
def test_purge(self):
pkgs = model.Session.query(model.Package).all()
for p in pkgs:
Expand Down
2 changes: 1 addition & 1 deletion doc/authorization.rst
Expand Up @@ -25,7 +25,7 @@ In more detail, these concepts are as follows:
* To simplify mapping users to actions and objects, actions are aggregated into a set of **roles**. For example, an editor role would automatically have edit and read actions.
* Finally, CKAN has registered **users**.

Recent support for authorization profiles has been implemented using a publisher/group based profile that is described in :doc:`publisher_auth_profile`
Recent support for authorization profiles has been implemented using a publisher/group based profile that is described in :doc:`publisher-profile`.

Objects
+++++++
Expand Down

0 comments on commit a9385df

Please sign in to comment.