def test_group_dictize_with_package_count(self):
        # group_list_dictize calls it like this by default
        group_ = factories.Group()
        factories.Dataset(groups=[{'name': group_['name']}])
        group_obj = model.Session.query(model.Group).filter_by().first()
        context = {'model': model, 'session': model.Session,
                   'dataset_counts': model_dictize.get_group_dataset_counts()
                   }

        group = model_dictize.group_dictize(group_obj, context,
                                            packages_field='dataset_count')
        assert_equal(group['package_count'], 1)
Ejemplo n.º 2
0
    def test_group_dictize_for_org_with_package_count(self):
        # group_list_dictize calls it like this by default
        org_ = factories.Organization()
        factories.Dataset(owner_org=org_['id'])
        org_obj = model.Session.query(model.Group).filter_by().first()
        context = {'model': model, 'session': model.Session,
                   'dataset_counts': model_dictize.get_group_dataset_counts()
                   }

        org = model_dictize.group_dictize(org_obj, context,
                                          packages_field='dataset_count')

        assert_equal(org['packages'], 1)
    def test_group_dictize_for_org_with_package_count(self):
        # group_list_dictize calls it like this by default
        org_ = factories.Organization()
        factories.Dataset(owner_org=org_['id'])
        org_obj = model.Session.query(model.Group).filter_by().first()
        context = {'model': model, 'session': model.Session,
                   'dataset_counts': model_dictize.get_group_dataset_counts()
                   }

        org = model_dictize.group_dictize(org_obj, context,
                                          packages_field='dataset_count')

        assert_equal(org['package_count'], 1)
Ejemplo n.º 4
0
def group_tree_filtered(context, data_dict):
    currentuser = context['user']
    sysadmin = authz.is_sysadmin(currentuser)

    model = context['model']
    group_type = data_dict.get('type', 'group')

    group_counts = model_dictize.get_group_dataset_counts()['owner_org']

    filtered_groups = []
    for group in model.Group.get_top_level_groups(type=group_type):
        branch = _group_tree_branch(group, type=group_type, group_counts=None if sysadmin else group_counts)
        if len(branch['children']) > 0 or branch['id'] in group_counts or sysadmin:
            filtered_groups.append(branch)

    return filtered_groups
Ejemplo n.º 5
0
    def test_group_dictize_with_package_count(self):
        # group_list_dictize calls it like this by default
        group_obj = factories.Group.model()
        other_group_obj = factories.Group.model()
        factories.Dataset(groups=[{"name": group_obj.name}])
        factories.Dataset(groups=[{"name": other_group_obj.name}])
        context = {
            "model": model,
            "session": model.Session,
            "dataset_counts": model_dictize.get_group_dataset_counts(),
        }

        group = model_dictize.group_dictize(
            group_obj, context, packages_field="dataset_count"
        )
        assert group["package_count"] == 1
Ejemplo n.º 6
0
    def test_group_dictize_for_org_with_package_count(self):
        # group_list_dictize calls it like this by default
        org_obj = factories.Organization.model()
        other_org_ = factories.Organization()
        factories.Dataset(owner_org=org_obj.id)
        factories.Dataset(owner_org=other_org_["id"])
        context = {
            "model": model,
            "session": model.Session,
            "dataset_counts": model_dictize.get_group_dataset_counts(),
        }

        org = model_dictize.group_dictize(
            org_obj, context, packages_field="dataset_count"
        )

        assert org["package_count"] == 1