コード例 #1
0
    def test_does_not_double_count(self, sysadmins, editors_and_admins):
        '''If the same user is both an editor/admin and a sysadmin, they
        should not be counted twice towards max_editors.

        '''
        sysadmins.return_value = ['user_1', 'user_2']
        editors_and_admins.return_value = ['user_1']

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=3)

        assert result['success'] is True
コード例 #2
0
    def test_does_count_duplicates_once(self, sysadmins, editors_and_admins):
        '''If the same user is both an editor/admin and a sysadmin, they
        *should* be counted once towards max_editors.

        '''
        sysadmins.return_value = ['user_1', 'user_2', 'user_3']
        editors_and_admins.return_value = ['user_1']

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=3)

        assert result['success'] is False
コード例 #3
0
    def test_with_max_editors_0(self, sysadmins, editors_and_admins):
        '''If max_editors is 0 and there are no editors/admins/sysadmins you
        still shouldn't be allowed to create a new editor.

        '''
        sysadmins.return_value = []
        editors_and_admins.return_value = []

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=0)

        assert result['success'] is False
コード例 #4
0
    def test_with_2_editors_and_1_sysadmin(self, sysadmins, editors_and_admins):
        '''If the number of editors/admins/sysadmins is equal to max_editors,
        then member_create should not allow a new editor to be created.

        '''
        sysadmins.return_value = ['sysadmin']
        editors_and_admins.return_value = ['editor_1', 'editor_2']

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=3)

        assert result['success'] is False
コード例 #5
0
    def test_with_1_editor_and_1_admin(self, sysadmins, editors_and_admins):
        '''If there are less than max_editors editors/admins/sysadmins then
        member_create should allow creating a new editor.

        '''
        sysadmins.return_value = ['sysadmin']
        editors_and_admins.return_value = ['editor']

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=3)

        assert result['success'] is True
コード例 #6
0
    def test_with_no_editors(self, sysadmins, editors_and_admins):
        '''If there are no editors, admins or sysadmins and max_editors > 0
        then member_create should allow creating a new editor.

        '''
        sysadmins.return_value = []
        editors_and_admins.return_value = []

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=3)

        assert result['success'] is True
コード例 #7
0
    def test_with_5_editors_and_max_editors_5(self, sysadmins,
                                              editors_and_admins):
        '''If max_editors is 5 and there are 5 editors/admins/sysadmins
        then you shouldn't be able to create another editor.

        '''
        sysadmins.return_value = ['sysadmin_1', 'sysadmin_2', 'sysadmin_3']
        editors_and_admins.return_value = ['editor', 'admin']

        result = plugin._member_create(_editor_create_data_dict(),
                                       {'success': True}, max_editors=5)

        assert result['success'] is False
コード例 #8
0
    def test_returns_False_when_core_returns_False(self, sysadmins,
                                                   editors_and_admins):
        '''If the result from the core member_create auth function has
        'success': False then the custom auth function should return that
        result, even if it would otherwise have returned 'success': True.

        '''
        sysadmins.return_value = ['user_1']
        editors_and_admins.return_value = ['user_1']
        core_result = {'success': False, 'msg': 'CKAN core says no'}
        result = plugin._member_create(_editor_create_data_dict(),
                                       core_result, max_editors=3)

        assert result == core_result
コード例 #9
0
    def test_can_still_create_members(self, sysadmins, editors_and_admins):
        '''It should still be possible to create (non-editor) group/org
        members, even when the number of editors/admins/sysadmins is equal to
        max_editors.

        '''
        sysadmins.return_value = ['user_1', 'user_2']
        editors_and_admins.return_value = ['user_3']

        # A data_dict similar to what would be passed to the member_create
        # action function to create a normal (non-editor) member.
        data_dict = {'id': 'fake_organization_id',
                     'object': 'fake_user_id',
                     'object_type': 'user',
                     'capacity': 'member'}

        result = plugin._member_create(data_dict, {'success': True},
                                       max_editors=3)

        assert result['success'] is True
コード例 #10
0
    def test_cannot_create_too_many_admins(self, sysadmins,
                                           editors_and_admins):
        '''If there are already max_editors editors/admins/sysadmins, it should
        not be possible to create another group/org admin.

        All the tests above tested creating group/org editors, this is just
        one test that creating admins is also blocked.

        '''
        sysadmins.return_value = ['user_1', 'user_2']
        editors_and_admins.return_value = ['user_3']

        # A data_dict similar to what would be passed to the member_create
        # action function to create a group or organization admin.
        data_dict = {'id': 'fake_organization_id',
                     'object': 'fake_user_id',
                     'object_type': 'user',
                     'capacity': 'admin'}

        result = plugin._member_create(data_dict, {'success': True},
                                       max_editors=3)

        assert result['success'] is False