Skip to content

Commit

Permalink
[master][tests]: Fix tests broken in #1521 branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jan 26, 2012
1 parent bc8b1ed commit aec525e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 32 deletions.
55 changes: 34 additions & 21 deletions ckan/tests/functional/test_group.py
@@ -1,3 +1,5 @@
import re

from nose.tools import assert_equal

from ckan.plugins import SingletonPlugin, implements, IGroupController
Expand Down Expand Up @@ -73,27 +75,6 @@ def test_index(self):
res = res.click(group_title)
assert groupname in res

def test_read(self):
# Relies on the search index being available
setup_test_search_index()
name = u'david'
title = u'Dave\'s books'
pkgname = u'warandpeace'
group = model.Group.by_name(name)
for group_ref in (group.name, group.id):
offset = url_for(controller='group', action='read', id=group_ref)
res = self.app.get(offset)
main_res = self.main_div(res)
assert title in res, res
#assert 'edit' not in main_res, main_res
assert 'Administrators' in res, res
assert 'russianfan' in main_res, main_res
assert name in res, res
assert '2 datasets found.' in self.strip_tags(main_res), main_res
pkg = model.Package.by_name(pkgname)
res = res.click(pkg.title)
assert '%s - Datasets' % pkg.title in res

def test_read_non_existent(self):
name = u'group_does_not_exist'
offset = url_for(controller='group', action='read', id=name)
Expand Down Expand Up @@ -123,6 +104,38 @@ def test_new_page(self):
res = self.app.get(offset, extra_environ={'REMOTE_USER': 'russianfan'})
assert 'Add A Group' in res, res

class TestGroupWithSearch(FunctionalTestCase):

@classmethod
def setup_class(self):
setup_test_search_index()
model.Session.remove()
CreateTestData.create()

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

def test_read(self):
# Relies on the search index being available
name = u'david'
title = u'Dave\'s books'
pkgname = u'warandpeace'
group = model.Group.by_name(name)
for group_ref in (group.name, group.id):
offset = url_for(controller='group', action='read', id=group_ref)
res = self.app.get(offset)
main_res = self.main_div(res)
assert title in res, res
#assert 'edit' not in main_res, main_res
assert 'Administrators' in res, res
assert 'russianfan' in main_res, main_res
assert name in res, res
no_datasets_found = int(re.search('(\d*) datasets found', main_res).groups()[0])
assert_equal(no_datasets_found, 2)
pkg = model.Package.by_name(pkgname)
res = res.click(pkg.title)
assert '%s - Datasets' % pkg.title in res

class TestEdit(FunctionalTestCase):

Expand Down
44 changes: 33 additions & 11 deletions ckan/tests/functional/test_pagination.py
Expand Up @@ -7,12 +7,17 @@
from ckan.tests import TestController, url_for, setup_test_search_index

def scrape_search_results(response, object_type):
assert object_type in ('dataset', 'group', 'user')
results = re.findall('href="/%s/%s_(\d\d)"' % (object_type, object_type),
str(response))
assert object_type in ('dataset', 'group_dataset', 'group', 'user')
if object_type is not 'group_dataset':
results = re.findall('href="/%s/%s_(\d\d)"' % (object_type, object_type),
str(response))
else:
object_type = 'dataset'
results = re.findall('class="main-link" href="/%s/%s_(\d\d)"' % (object_type, object_type),
str(response))
return results

def test_scrape():
def test_scrape_user():
html = '''
<li class="username">
<img src="http://gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s=16&amp;d=http://test.ckan.net/images/icons/user.png" /> <a href="/user/user_00">user_00</a>
Expand All @@ -25,6 +30,24 @@ def test_scrape():
'''
res = scrape_search_results(html, 'user')
assert_equal(res, ['00', '01'])

def test_scrape_group_dataset():
html = '''
<div class="search-result ">
<a class="view-more-link" href="/dataset/dataset_13">View</a>
<a class="main-link" href="/dataset/dataset_13">dataset_13</a>
<p class="result-description"></p>
<span class="result-url">
<img src="/images/icons/lock.png" height="16px" width="16px" alt="None" /> Not Openly Licensed
</span>
</div>
'''
res = scrape_search_results(html, 'group_dataset')
assert_equal(res, ['13'])

class TestPaginationPackage(TestController):
@classmethod
Expand Down Expand Up @@ -61,18 +84,17 @@ def test_package_search_p2(self):
pkg_numbers = scrape_search_results(res, 'dataset')
assert_equal(['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39'], pkg_numbers)

def test_group_read_p1(self):
def test_group_datasets_read_p1(self):
res = self.app.get(url_for(controller='group', action='read', id='group_00'))
assert 'href="/group/group_00?page=2' in res
print res.body
pkg_numbers = scrape_search_results(res, 'dataset')
assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29'], pkg_numbers)
pkg_numbers = scrape_search_results(res, 'group_dataset')
assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'], pkg_numbers)

def test_group_read_p2(self):
def test_group_datasets_read_p2(self):
res = self.app.get(url_for(controller='group', action='read', id='group_00', page=2))
assert 'href="/group/group_00?page=1' in res
pkg_numbers = scrape_search_results(res, 'dataset')
assert_equal(['30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50'], pkg_numbers)
pkg_numbers = scrape_search_results(res, 'group_dataset')
assert_equal(['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39'], pkg_numbers)

class TestPaginationGroup(TestController):
@classmethod
Expand Down

0 comments on commit aec525e

Please sign in to comment.