예제 #1
0
    def test_showcase_admin_add_multiple_users(self):
        """
        Calling ckanext_showcase_admin_add for multiple users correctly adds
        them to showcase admin list.
        """
        user_to_add = factories.User()
        second_user_to_add = factories.User()

        assert model.Session.query(ShowcaseAdmin).count() == 0

        helpers.call_action(
            "ckanext_showcase_admin_add",
            context={},
            username=user_to_add["name"],
        )

        helpers.call_action(
            "ckanext_showcase_admin_add",
            context={},
            username=second_user_to_add["name"],
        )

        assert model.Session.query(ShowcaseAdmin).count() == 2
        assert user_to_add["id"] in ShowcaseAdmin.get_showcase_admin_ids()
        assert (second_user_to_add["id"]
                in ShowcaseAdmin.get_showcase_admin_ids())
예제 #2
0
def showcase_admin_list(context, data_dict):
    '''
    Return a list of dicts containing the id and name of all active showcase
    admin users.

    :rtype: list of dictionaries
    '''

    toolkit.check_access('ckanext_showcase_admin_list', context, data_dict)

    model = context["model"]

    user_ids = ShowcaseAdmin.get_showcase_admin_ids()

    if user_ids:
        q = model.Session.query(model.User) \
            .filter(model.User.state == 'active') \
            .filter(model.User.id.in_(user_ids))

        showcase_admin_list = []
        for user in q.all():
            showcase_admin_list.append({'name': user.name, 'id': user.id})
        return showcase_admin_list

    return []
예제 #3
0
def showcase_admin_list(context, data_dict):
    '''
    Return a list of dicts containing the id and name of all active showcase
    admin users.

    :rtype: list of dictionaries
    '''

    toolkit.check_access('ckanext_showcase_admin_list', context, data_dict)

    model = context["model"]

    user_ids = ShowcaseAdmin.get_showcase_admin_ids()

    if user_ids:
        q = model.Session.query(model.User) \
            .filter(model.User.state == 'active') \
            .filter(model.User.id.in_(user_ids))

        showcase_admin_list = []
        for user in q.all():
            showcase_admin_list.append({'name': user.name, 'id': user.id})
        return showcase_admin_list

    return []
예제 #4
0
    def test_showcase_admin_add_multiple_users(self):
        '''
        Calling ckanext_showcase_admin_add for multiple users correctly adds
        them to showcase admin list.
        '''
        user_to_add = factories.User()
        second_user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user_to_add['name'])

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=second_user_to_add['name'])

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 2)
        nosetools.assert_true(user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
        nosetools.assert_true(second_user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
예제 #5
0
    def test_showcase_admin_add_multiple_users(self):
        '''
        Calling ckanext_showcase_admin_add for multiple users correctly adds
        them to showcase admin list.
        '''
        user_to_add = factories.User()
        second_user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user_to_add['name'])

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=second_user_to_add['name'])

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 2)
        nosetools.assert_true(user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
        nosetools.assert_true(second_user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
예제 #6
0
    def test_showcase_admin_add_no_args(self):
        '''
        Calling ckanext_showcase_admin_add with no args raises ValidationError
        and no ShowcaseAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ValidationError, helpers.call_action,
                                'ckanext_showcase_admin_add', context={})

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #7
0
    def test_showcase_admin_add_no_args(self):
        '''
        Calling ckanext_showcase_admin_add with no args raises ValidationError
        and no ShowcaseAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ValidationError, helpers.call_action,
                                'ckanext_showcase_admin_add', context={})

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #8
0
    def test_showcase_admin_add_username_doesnot_exist(self):
        '''
        Calling ckanext_showcase_admin_add with non-existent username raises
        ValidationError and no ShowcaseAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ObjectNotFound, helpers.call_action,
                                'ckanext_showcase_admin_add', context={},
                                username='******')

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #9
0
    def test_showcase_admin_add_username_doesnot_exist(self):
        '''
        Calling ckanext_showcase_admin_add with non-existent username raises
        ValidationError and no ShowcaseAdmin object is created.
        '''
        nosetools.assert_raises(toolkit.ObjectNotFound, helpers.call_action,
                                'ckanext_showcase_admin_add', context={},
                                username='******')

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #10
0
    def test_showcase_admin_add_no_args(self):
        """
        Calling ckanext_showcase_admin_add with no args raises ValidationError
        and no ShowcaseAdmin object is created.
        """
        with pytest.raises(toolkit.ValidationError):
            helpers.call_action(
                "ckanext_showcase_admin_add",
                context={},
            )

        assert model.Session.query(ShowcaseAdmin).count() == 0
        assert ShowcaseAdmin.get_showcase_admin_ids() == []
예제 #11
0
    def test_showcase_admin_delete_user_removes_showcase_admin_object(self):
        '''
        Deleting a user also deletes the corresponding ShowcaseAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user['name'])

        # There's a ShowcaseAdmin object
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)
        nosetools.assert_true(user['id'] in ShowcaseAdmin.get_showcase_admin_ids())

        # purge the user, should also delete the ShowcaseAdmin object
        # associated with it.
        user_obj = model.Session.query(model.User).get(user['id'])
        user_obj.purge()
        model.repo.commit_and_remove()

        # The ShowcaseAdmin has also been removed
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #12
0
    def test_showcase_admin_add_creates_showcase_admin_user(self):
        '''
        Calling ckanext_showcase_admin_add adds user to showcase admin list.
        '''
        user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user_to_add['name'])

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)
        nosetools.assert_true(user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
예제 #13
0
    def test_showcase_admin_add_creates_showcase_admin_user(self):
        '''
        Calling ckanext_showcase_admin_add adds user to showcase admin list.
        '''
        user_to_add = factories.User()

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user_to_add['name'])

        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)
        nosetools.assert_true(user_to_add['id'] in ShowcaseAdmin.get_showcase_admin_ids())
예제 #14
0
    def test_showcase_admin_delete_user_removes_showcase_admin_object(self):
        '''
        Deleting a user also deletes the corresponding ShowcaseAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user['name'])

        # There's a ShowcaseAdmin object
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)
        nosetools.assert_true(user['id'] in ShowcaseAdmin.get_showcase_admin_ids())

        # purge the user, should also delete the ShowcaseAdmin object
        # associated with it.
        user_obj = model.Session.query(model.User).get(user['id'])
        user_obj.purge()
        model.repo.commit_and_remove()

        # The ShowcaseAdmin has also been removed
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #15
0
    def test_showcase_admin_delete_user_removes_showcase_admin_object(self):
        """
        Deleting a user also deletes the corresponding ShowcaseAdmin object.
        """
        user = factories.User()

        helpers.call_action("ckanext_showcase_admin_add",
                            context={},
                            username=user["name"])

        # There's a ShowcaseAdmin object
        assert model.Session.query(ShowcaseAdmin).count() == 1
        assert user["id"] in ShowcaseAdmin.get_showcase_admin_ids()

        # purge the user, should also delete the ShowcaseAdmin object
        # associated with it.
        user_obj = model.Session.query(model.User).get(user["id"])
        user_obj.purge()
        model.repo.commit_and_remove()

        # The ShowcaseAdmin has also been removed
        assert model.Session.query(ShowcaseAdmin).count() == 0
        assert ShowcaseAdmin.get_showcase_admin_ids() == []
예제 #16
0
    def test_showcase_admin_add_username_doesnot_exist(self):
        """
        Calling ckanext_showcase_admin_add with non-existent username raises
        ValidationError and no ShowcaseAdmin object is created.
        """
        with pytest.raises(toolkit.ObjectNotFound):
            helpers.call_action(
                "ckanext_showcase_admin_add",
                context={},
                username="******",
            )

        assert model.Session.query(ShowcaseAdmin).count() == 0
        assert ShowcaseAdmin.get_showcase_admin_ids() == []
예제 #17
0
    def test_showcase_admin_add_creates_showcase_admin_user(self):
        """
        Calling ckanext_showcase_admin_add adds user to showcase admin list.
        """
        user_to_add = factories.User()

        assert model.Session.query(ShowcaseAdmin).count() == 0

        helpers.call_action(
            "ckanext_showcase_admin_add",
            context={},
            username=user_to_add["name"],
        )

        assert model.Session.query(ShowcaseAdmin).count() == 1
        assert user_to_add["id"] in ShowcaseAdmin.get_showcase_admin_ids()
예제 #18
0
    def test_showcase_admin_remove_deletes_showcase_admin_user(self):
        '''
        Calling ckanext_showcase_admin_remove deletes ShowcaseAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user['name'])

        # There's a ShowcaseAdmin obj
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)

        helpers.call_action('ckanext_showcase_admin_remove', context={},
                            username=user['name'])

        # There's no ShowcaseAdmin obj
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #19
0
    def test_showcase_admin_remove_deletes_showcase_admin_user(self):
        '''
        Calling ckanext_showcase_admin_remove deletes ShowcaseAdmin object.
        '''
        user = factories.User()

        helpers.call_action('ckanext_showcase_admin_add', context={},
                            username=user['name'])

        # There's a ShowcaseAdmin obj
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 1)

        helpers.call_action('ckanext_showcase_admin_remove', context={},
                            username=user['name'])

        # There's no ShowcaseAdmin obj
        nosetools.assert_equal(model.Session.query(ShowcaseAdmin).count(), 0)
        nosetools.assert_equal(ShowcaseAdmin.get_showcase_admin_ids(), [])
예제 #20
0
    def test_showcase_admin_remove_deletes_showcase_admin_user(self):
        """
        Calling ckanext_showcase_admin_remove deletes ShowcaseAdmin object.
        """
        user = factories.User()

        helpers.call_action("ckanext_showcase_admin_add",
                            context={},
                            username=user["name"])

        # There's a ShowcaseAdmin obj
        assert model.Session.query(ShowcaseAdmin).count() == 1

        helpers.call_action("ckanext_showcase_admin_remove",
                            context={},
                            username=user["name"])

        # There's no ShowcaseAdmin obj
        assert model.Session.query(ShowcaseAdmin).count() == 0
        assert ShowcaseAdmin.get_showcase_admin_ids() == []