Skip to content

Commit

Permalink
[#1038] Test data is now organizations rather than groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Jul 23, 2013
1 parent fde50fa commit 2c0bbaf
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
34 changes: 26 additions & 8 deletions ckan/lib/create_test_data.py
Expand Up @@ -231,8 +231,12 @@ def create_arbitrary(cls, package_dicts, relationships=[],
# session has not yet been committed at this point.
# Fetch from the new_groups dict instead.
group = new_groups[group_name]
member = model.Member(group=group, table_id=pkg.id, table_name='package')
capacity = 'organization' if group.is_organization \
else 'public'
member = model.Member(group=group, table_id=pkg.id, table_name='package', capacity=capacity)
model.Session.add(member)
if group.is_organization:
pkg.owner_org = group.id
elif attr == 'license':
pkg.license_id = val
elif attr == 'license_id':
Expand Down Expand Up @@ -330,7 +334,8 @@ def create_groups(cls, group_dicts, admin_user_name=None, auth_profile=""):
else:
admin_users = []
assert isinstance(group_dicts, (list, tuple))
group_attributes = set(('name', 'title', 'description', 'parent_id'))
group_attributes = set(('name', 'title', 'description', 'parent_id',
'type', 'is_organization'))
for group_dict in group_dicts:
if model.Group.by_name(unicode(group_dict['name'])):
log.warning('Cannot create group "%s" as it already exists.' % \
Expand Down Expand Up @@ -861,26 +866,39 @@ def make_some_vocab_tags(cls):
group_hierarchy_groups = [
{'name': 'department-of-health',
'title': 'Department of Health',
'contact-email': 'contact@doh.gov.uk'},
'contact-email': 'contact@doh.gov.uk',
'type': 'organization',
'is_organization': True
},
{'name': 'food-standards-agency',
'title': 'Food Standards Agency',
'contact-email': 'contact@fsa.gov.uk',
'parent': 'department-of-health'},
'parent': 'department-of-health',
'type': 'organization',
'is_organization': True},
{'name': 'national-health-service',
'title': 'National Health Service',
'contact-email': 'contact@nhs.gov.uk',
'parent': 'department-of-health'},
'parent': 'department-of-health',
'type': 'organization',
'is_organization': True},
{'name': 'nhs-wirral-ccg',
'title': 'NHS Wirral CCG',
'contact-email': 'contact@wirral.nhs.gov.uk',
'parent': 'national-health-service'},
'parent': 'national-health-service',
'type': 'organization',
'is_organization': True},
{'name': 'nhs-southwark-ccg',
'title': 'NHS Southwark CCG',
'contact-email': 'contact@southwark.nhs.gov.uk',
'parent': 'national-health-service'},
'parent': 'national-health-service',
'type': 'organization',
'is_organization': True},
{'name': 'cabinet-office',
'title': 'Cabinet Office',
'contact-email': 'contact@cabinet-office.gov.uk'},
'contact-email': 'contact@cabinet-office.gov.uk',
'type': 'organization',
'is_organization': True},
]

group_hierarchy_datasets = [
Expand Down
18 changes: 10 additions & 8 deletions ckan/tests/models/test_group.py
Expand Up @@ -97,14 +97,16 @@ def _search_results(self, query, is_org=False):
name_set_from_groups = lambda groups: set([group.name for group in groups])
names_from_groups = lambda groups: [group.name for group in groups]

group_type = 'organization'

class TestHierarchy:
@classmethod
def setup_class(self):
CreateTestData.create_group_hierarchy_test_data()

def test_get_children_groups(self):
res = model.Group.by_name(u'department-of-health').\
get_children_groups()
get_children_groups(type=group_type)
# check groups
assert_equal(name_set_from_dicts(res),
set(('national-health-service',
Expand All @@ -116,42 +118,42 @@ def test_get_children_groups(self):

def test_get_children_group_hierarchy__from_top(self):
assert_equal(name_set_from_group_tuple(model.Group.by_name(u'department-of-health').\
get_children_group_hierarchy()),
get_children_group_hierarchy(type=group_type)),
set(('national-health-service', 'food-standards-agency',
'nhs-wirral-ccg', 'nhs-southwark-ccg')))
# i.e. not cabinet-office

def test_get_children_group_hierarchy__from_tier_two(self):
assert_equal(name_set_from_group_tuple(model.Group.by_name(u'national-health-service').\
get_children_group_hierarchy()),
get_children_group_hierarchy(type=group_type)),
set(('nhs-wirral-ccg',
'nhs-southwark-ccg')))
# i.e. not department-of-health or food-standards-agency

def test_get_children_group_hierarchy__from_bottom_tier(self):
assert_equal(name_set_from_group_tuple(model.Group.by_name(u'nhs-wirral-ccg').\
get_children_group_hierarchy()),
get_children_group_hierarchy(type=group_type)),
set())

def test_get_parent_groups_up_hierarchy__from_top(self):
assert_equal(names_from_groups(model.Group.by_name(u'department-of-health').\
get_parent_group_hierarchy()),
get_parent_group_hierarchy(type=group_type)),
[])

def test_get_parent_groups_up_hierarchy__from_tier_two(self):
assert_equal(names_from_groups(model.Group.by_name(u'national-health-service').\
get_parent_group_hierarchy()),
get_parent_group_hierarchy(type=group_type)),
['department-of-health'])

def test_get_parent_groups_up_hierarchy__from_tier_three(self):
assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
get_parent_group_hierarchy()),
get_parent_group_hierarchy(type=group_type)),
['department-of-health',
'national-health-service'])

def test_get_top_level_groups(self):
assert_equal(names_from_groups(model.Group.by_name(u'nhs-wirral-ccg').\
get_top_level_groups()),
get_top_level_groups(type=group_type)),
['cabinet-office', 'department-of-health'])

class TestGroupRevisions:
Expand Down

0 comments on commit 2c0bbaf

Please sign in to comment.