Skip to content

Commit

Permalink
[tests] ckan#662 Fix broken tests from the fix for this ticket in cse…
Browse files Browse the repository at this point in the history
…t:00038ef33c45.
  • Loading branch information
David Read committed Mar 28, 2011
1 parent 1071e0e commit 7d10ba5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ckan/lib/create_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def create(cls, commit_changesets=False):
pkg2.tags = [ tag1 ]
cls.tag_names = [u'russian', u'tolstoy']
pkg1.license_id = u'other-open'
pkg2.license_id = u'cc-by'
pkg2.license_id = u'cc-nc' # closed license
pkg2.title = u'A Wonderful Story'
pkg1.extras = {u'genre':'romantic novel',
u'original media':'book'}
Expand Down
1 change: 1 addition & 0 deletions ckan/tests/forms/test_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class TestGroupFieldset(PylonsTestCase):
@classmethod
def setup_class(self):
PylonsTestCase.setup_class()
ckan.tests.CreateTestData.create()

@classmethod
Expand Down
12 changes: 8 additions & 4 deletions ckan/tests/functional/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ def _check_redirect(self, return_url_param, expected_redirect,
pkg.purge()
model.repo.commit_and_remove()

class TestReadOnly(TestPackageForm, HtmlCheckMethods, TestSearchIndexer):
class TestReadOnly(TestPackageForm, HtmlCheckMethods, TestSearchIndexer, PylonsTestCase):

@classmethod
def setup_class(cls):
PylonsTestCase.setup_class()
cls.tsi = TestSearchIndexer()
CreateTestData.create()
cls.tsi.index()
Expand Down Expand Up @@ -294,7 +295,7 @@ def test_read(self):
for pkg_ in (pkg_by_name_main, pkg_by_id_main):
pkg_ = pkg_.replace(txt, 'placeholder')
res_diff = self.diff_html(pkg_by_name_main, pkg_by_id_main)
assert not res_diff, res_diff
assert not res_diff, res_diff.encode('utf8')
# not true as language selection link return url differs:
#assert len(res_by_id.body) == len(res.body)

Expand Down Expand Up @@ -342,8 +343,11 @@ def test_read_internal_links(self):
offset = url_for(controller='package', action='read', id=pkg_name)
res = self.app.get(offset)
def check_link(res, controller, id):
link = '<a href="/%s/read/%s">%s:%s</a>' % (controller, id, controller, id)
assert link in res, self.main_div(res) + link
link = '<a href="/%s/%s">%s:%s</a>' % (controller, id, controller, id)
if link not in res:
print self.main_div(res).encode('utf8')
print 'Missing link: %r' % link
raise AssertionError
check_link(res, 'package', 'pkg-1')
check_link(res, 'tag', 'tag_1')
check_link(res, 'group', 'test-group-1')
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/functional/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_user_read(self):
main_res = self.main_div(res)
assert 'annafan - User' in res, res
assert 'Logged in' not in main_res, main_res
assert 'About' in main_res, main_res
assert 'about' in main_res, main_res
assert 'I love reading Annakarenina' in res, main_res
assert 'Edit' not in main_res, main_res
assert 'Number of edits:</strong> 3' in res, res
Expand Down
6 changes: 5 additions & 1 deletion ckan/tests/html_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ class HtmlCheckMethods(object):
def named_div(self, div_name, html):
'strips html to just the <div id="DIV_NAME"> section'
the_html = html.body.decode('utf8')
div_html = the_html[the_html.find(u'<div id="%s"' % div_name):the_html.find(u'<!-- /%s -->' % div_name)]
start_div = the_html.find(u'<div id="%s"' % div_name)
end_div = the_html.find(u'<!-- #%s -->' % div_name)
if end_div == -1:
end_div = the_html.find(u'<!-- /%s -->' % div_name)
div_html = the_html[start_div:end_div]
assert div_html
return div_html

Expand Down
31 changes: 16 additions & 15 deletions ckan/tests/pylons_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,24 @@ def ungettext(self, singular, plural, n):

class PylonsTestCase(object):
"""A basic test case which allows access to pylons.c and pylons.request.
"""
def setup(self):
self.registry=Registry()
self.registry.prepare()

self.context_obj=ContextObj()
self.registry.register(pylons.c, self.context_obj)
"""
@classmethod
def setup_class(cls):
cls.registry=Registry()
cls.registry.prepare()

cls.context_obj=ContextObj()
cls.registry.register(pylons.c, cls.context_obj)
pylons.c.errors = None

self.request_obj=Request(dict(HTTP_HOST="nohost"))
self.registry.register(pylons.request, self.request_obj)
cls.request_obj=Request(dict(HTTP_HOST="nohost"))
cls.registry.register(pylons.request, cls.request_obj)

self.translator_obj=MockTranslator()
self.registry.register(pylons.translator, self.translator_obj)
cls.translator_obj=MockTranslator()
cls.registry.register(pylons.translator, cls.translator_obj)

self.buffet = pylons.templating.Buffet('genshi', template_root='ckan.templates')
self.registry.register(pylons.buffet, self.buffet)
cls.buffet = pylons.templating.Buffet('genshi', template_root='ckan.templates')
cls.registry.register(pylons.buffet, cls.buffet)

self.registry.register(pylons.response, Response())
self.registry.register(pylons.url, None)
cls.registry.register(pylons.response, Response())
cls.registry.register(pylons.url, None)

0 comments on commit 7d10ba5

Please sign in to comment.