예제 #1
0
파일: test_group.py 프로젝트: Atharex/ckan
 def test_groups_allowed_to_be_its_parent(self):
     groups = model.Group.by_name(u'national-health-service').\
         groups_allowed_to_be_its_parent(type=group_type)
     names = names_from_groups(groups)
     assert_in('department-of-health', names)
     assert_in('cabinet-office', names)
     assert_not_in('natonal-health-service', names)
     assert_not_in('nhs-wirral-ccg', names)
예제 #2
0
 def test_groups_allowed_to_be_its_parent(self):
     groups = model.Group.by_name(u'national-health-service').\
         groups_allowed_to_be_its_parent(type=group_type)
     names = names_from_groups(groups)
     assert_in('department-of-health', names)
     assert_in('cabinet-office', names)
     assert_not_in('natonal-health-service', names)
     assert_not_in('nhs-wirral-ccg', names)
예제 #3
0
파일: test_group.py 프로젝트: Atharex/ckan
 def test_get_children_group_hierarchy__from_top_2(self):
     groups = model.Group.by_name(u'department-of-health').\
             get_children_group_hierarchy(type=group_type)
     # the first group must be NHS or Food Standards Agency - i.e. on the
     # first level down
     nhs = groups[0]
     assert_in(nhs[1], ('national-health-service', 'food-standards-agency'))
     assert_equal(model.Group.get(nhs[3]).name, 'department-of-health')
예제 #4
0
 def test_get_children_group_hierarchy__from_top_2(self):
     groups = model.Group.by_name(u'department-of-health').\
             get_children_group_hierarchy(type=group_type)
     # the first group must be NHS or Food Standards Agency - i.e. on the
     # first level down
     nhs = groups[0]
     assert_in(nhs[1], ('national-health-service', 'food-standards-agency'))
     assert_equal(model.Group.get(nhs[3]).name, 'department-of-health')
예제 #5
0
파일: test_group.py 프로젝트: Atharex/ckan
 def test_get_children_groups(self):
     res = model.Group.by_name(u'department-of-health').\
           get_children_groups(type=group_type)
     # check groups
     assert_equal(name_set_from_groups(res),
                  set(('national-health-service',
                       'food-standards-agency')))
     # check each group is a Group
     assert isinstance(res[0], model.Group)
     assert_in(res[0].name, ('national-health-service', 'food-standards-agency'))
     assert_in(res[0].title, ('National Health Service', 'Food Standards Agency'))
예제 #6
0
 def test_get_children_groups(self):
     res = model.Group.by_name(u'department-of-health').\
           get_children_groups(type=group_type)
     # check groups
     assert_equal(name_set_from_groups(res),
                  set(('national-health-service',
                       'food-standards-agency')))
     # check each group is a Group
     assert isinstance(res[0], model.Group)
     assert_in(res[0].name, ('national-health-service', 'food-standards-agency'))
     assert_in(res[0].title, ('National Health Service', 'Food Standards Agency'))
예제 #7
0
    def test_21_package_dictization_with_deleted_group(self):
        """
        Ensure that the dictization does not return groups that the dataset has
        been removed from.
        """
        # Create a new dataset and 2 new groups
        model.repo.new_revision()
        pkg = model.Package(name='testing-deleted-groups')
        group_1 = model.Group(name='test-group-1')
        group_2 = model.Group(name='test-group-2')
        model.Session.add(pkg)
        model.Session.add(group_1)
        model.Session.add(group_2)
        model.Session.flush()

        # Add the dataset to group_1, and signal that the dataset used
        # to be a member of group_2 by setting its membership state to 'deleted'
        membership_1 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_1,
                                    group_id = group_1.id,
                                    state = 'active')

        membership_2 = model.Member(table_id = pkg.id,
                                    table_name = 'package',
                                    group = group_2,
                                    group_id = group_2.id,
                                    state = 'deleted')

        model.Session.add(membership_1)
        model.Session.add(membership_2)
        model.repo.commit()

        # Dictize the dataset
        context = {"model": model,
                   "session": model.Session}

        result = package_dictize(pkg, context)
        self.remove_changable_columns(result)
        assert_not_in('test-group-2', [ g['name'] for g in result['groups'] ])
        assert_in('test-group-1', [ g['name'] for g in result['groups'] ])
    def test_21_package_dictization_with_deleted_group(self):
        """
        Ensure that the dictization does not return groups that the dataset has
        been removed from.
        """
        # Create a new dataset and 2 new groups
        model.repo.new_revision()
        pkg = model.Package(name='testing-deleted-groups')
        group_1 = model.Group(name='test-group-1')
        group_2 = model.Group(name='test-group-2')
        model.Session.add(pkg)
        model.Session.add(group_1)
        model.Session.add(group_2)
        model.Session.flush()

        # Add the dataset to group_1, and signal that the dataset used
        # to be a member of group_2 by setting its membership state to 'deleted'
        membership_1 = model.Member(table_id=pkg.id,
                                    table_name='package',
                                    group=group_1,
                                    group_id=group_1.id,
                                    state='active')

        membership_2 = model.Member(table_id=pkg.id,
                                    table_name='package',
                                    group=group_2,
                                    group_id=group_2.id,
                                    state='deleted')

        model.Session.add(membership_1)
        model.Session.add(membership_2)
        model.repo.commit()

        # Dictize the dataset
        context = {"model": model, "session": model.Session}

        result = package_dictize(pkg, context)
        self.remove_changable_columns(result)
        assert_not_in('test-group-2', [g['name'] for g in result['groups']])
        assert_in('test-group-1', [g['name'] for g in result['groups']])