python类assert_true()的实例源码

test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_powerview_create_title_missing(self):
        '''Missing title raises ValidationError.'''
        sysadmin = Sysadmin()

        data_dict = self._make_create_data_dict()
        # remove title key
        del data_dict['title']
        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_create')(
                context={'user': sysadmin['name']},
                data_dict=data_dict
            )
        error_dict = cm.exception.error_dict['title']
        nosetools.assert_true("Missing value"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_powerview_create_view_type_missing(self):
        '''Missing view_type raises ValidationError.'''
        sysadmin = Sysadmin()

        data_dict = self._make_create_data_dict()
        # remove title key
        del data_dict['view_type']
        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_create')(
                context={'user': sysadmin['name']},
                data_dict=data_dict
            )
        error_dict = cm.exception.error_dict['view_type']
        nosetools.assert_true("Missing value"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_powerview_create_config_must_be_json(self):
        '''If present, config must be a json string.'''
        sysadmin = Sysadmin()

        data_dict = self._make_create_data_dict()
        # replace config with non-json string
        data_dict['config'] = "I'm not json."
        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_create')(
                context={'user': sysadmin['name']},
                data_dict=data_dict
            )
        error_dict = cm.exception.error_dict['config']
        nosetools.assert_true("Could not parse as valid JSON"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_powerview_update_no_id(self):
        '''Updating with a missing powerview id raises error.'''

        sysadmin = Sysadmin()

        powerview_dict = factories.PowerView()
        del powerview_dict['id']

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_update')(
                context={'user': sysadmin['name']},
                data_dict=powerview_dict
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Missing value"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_powerview_update_nonexisting_id(self):
        '''Updating with a non-existing powerview id raises error.'''

        sysadmin = Sysadmin()

        powerview_dict = factories.PowerView()
        powerview_dict['id'] = 'non-existing-id'

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_update')(
                context={'user': sysadmin['name']},
                data_dict=powerview_dict
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Not found: PowerView"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_powerview_show_no_id(self):
        '''Calling powerview show with a missing id raises error.'''

        sysadmin = Sysadmin()

        factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_show')(
                context={'user': sysadmin['name']},
                data_dict={}
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Missing value"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_powerview_show_nonexisting_id(self):
        '''Calling powerview show with a non-existing id raises error.'''

        sysadmin = Sysadmin()

        factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_show')(
                context={'user': sysadmin['name']},
                data_dict={'id': 'non-existin-id'}
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Not found: PowerView"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_powerview_resource_list_nonexisting_id(self):
        '''Calling powerview resource list with a non-existing id raises
        error.'''
        sysadmin = Sysadmin()

        factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_resource_list')(
                context={'user': sysadmin['name']},
                data_dict={'id': 'non-existin-id'}
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Not found: PowerView"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_powerview_delete_no_id(self):
        '''Calling powerview delete with a missing id raises error.'''

        sysadmin = Sysadmin()

        factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_delete')(
                context={'user': sysadmin['name']},
                data_dict={}
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Missing value"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_powerview_delete_nonexisting_id(self):
        '''Calling powerview delete with a non-existing id raises error.'''

        sysadmin = Sysadmin()

        factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_delete')(
                context={'user': sysadmin['name']},
                data_dict={'id': 'non-existin-id'}
            )
        error_dict = cm.exception.error_dict['id']
        nosetools.assert_true("Not found: PowerView"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_powerview_add_resource_nonexisting_resource_id(self):
        '''Calling powerview_add_resource with nonexisting resource id raises
        ValidationError.'''
        sysadmin = Sysadmin()
        powerview = factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_add_resource')(
                context={'user': sysadmin['name']},
                data_dict={'id': powerview['id'],
                           'resource_id': 'non-existing-id'}
            )
        error_dict = cm.exception.error_dict['resource_id']
        nosetools.assert_true("Not found: Resource"
                              in error_dict,
                              "Expected string not in exception message.")
test_schema.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_powerview_remove_resource_nonexisting_resource_id(self):
        '''Calling powerview_remove_resource with nonexisting resource id raises
        ValidationError.'''
        sysadmin = Sysadmin()
        powerview = factories.PowerView()

        with nosetools.assert_raises(ValidationError) as cm:
            toolkit.get_action('powerview_remove_resource')(
                context={'user': sysadmin['name']},
                data_dict={'id': powerview['id'],
                           'resource_id': 'non-existing-id'}
            )
        error_dict = cm.exception.error_dict['resource_id']
        nosetools.assert_true("Not found: Resource"
                              in error_dict,
                              "Expected string not in exception message.")
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_powerview_create_normal_user_allow_create_authed_resources(self):
        '''
        Calling powerview create with normal user when allow_user_create is
        true, with authorized private resources doesn't raise NotAuthorized.
        '''
        a_user = factories.User()
        org = factories.Organization(users=[{
            'name': a_user['name'], 'capacity': 'member'}])
        dataset = factories.Dataset(owner_org=org['id'], private="true")
        r1 = factories.Resource(package_id=dataset['id'])
        r2 = factories.Resource(package_id=dataset['id'])

        pv_dict = self._make_create_data_dict(resources=[r1['id'], r2['id']])
        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(helpers.call_auth('ckanext_powerview_create',
                              context=context, **pv_dict))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_powerview_update_normal_user_allow_create_add_authed_resources(self):
        '''
        Calling powerview update with normal user when allow_user_create is
        true, with authorized private resources doesn't raise NotAuthorized.
        '''
        a_user = factories.User()
        org = factories.Organization(users=[{'name': a_user['name'],
                                             'capacity': 'member'}])
        dataset = factories.Dataset(owner_org=org['id'], private="true")
        r1 = factories.Resource(package_id=dataset['id'])
        r2 = factories.Resource(package_id=dataset['id'])

        pv = powerview_factories.PowerView(user=a_user, private=False)
        pv['resources'] = [r1['id'], r2['id']]

        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(helpers.call_auth('ckanext_powerview_update',
                                                context=context, **pv))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_powerview_add_resource_sysadmin(self):
        '''
        Calling powerview add resource for a sysadmin does not raise
        NotAuthorized.
        '''
        a_sysadmin = factories.Sysadmin()
        dataset = factories.Dataset()
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView()

        context = {'user': a_sysadmin['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_add_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_powerview_add_resource_normal_user_allow_create(self):
        '''
        Calling powerview add resource for a normal user does not raise
        NotAuthorized for an owned powerview and resource
        '''
        a_user = factories.User()
        dataset = factories.Dataset()
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(user=a_user)

        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_add_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_powerview_add_resource_normal_user_allow_create_authed_resource(self):
        '''
        Calling powerview add resource for a normal user doesn't raise
        NotAuthorized for an owned powerview and private authorized resource.
        '''
        a_user = factories.User()
        org = factories.Organization(users=[{'name': a_user['name'],
                                             'capacity': 'member'}])
        dataset = factories.Dataset(owner_org=org['id'], private="true")
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(user=a_user)

        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_add_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_powerview_remove_resource_sysadmin(self):
        '''
        Calling powerview remove resource for a sysadmin does not raise
        NotAuthorized.
        '''
        a_sysadmin = factories.Sysadmin()
        dataset = factories.Dataset()
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(resources=[r1['id']])

        context = {'user': a_sysadmin['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_remove_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_powerview_remove_resource_normal_user_allow_create(self):
        '''
        Calling powerview remove resource for a normal user does not raise
        NotAuthorized for an owned powerview and resource
        '''
        a_user = factories.User()
        dataset = factories.Dataset()
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(user=a_user,
                                                  resources=[r1['id']])

        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_remove_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def test_powerview_remove_resource_normal_user_allow_create_authed_resource(self):
        '''
        Calling powerview remove resource for a normal user doesn't raise
        NotAuthorized for an owned powerview and private authorized resource.
        '''
        a_user = factories.User()
        org = factories.Organization(users=[{'name': a_user['name'],
                                             'capacity': 'member'}])
        dataset = factories.Dataset(owner_org=org['id'], private="true")
        r1 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(user=a_user,
                                                  resources=[r1['id']])

        context = {'user': a_user['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_remove_resource',
                              context=context,
                              powerview_id=powerview['id'],
                              resource_id=r1['id']))
test_auth.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_powerview_resource_list_sysadmin_private_resources(self):
        '''
        Calling powerview resource list with a sysadmin on a powerview
        containing private resources, doesn't raise errors.
        '''
        a_sysadmin = factories.Sysadmin()
        org = factories.Organization()
        dataset = factories.Dataset(owner_org=org['id'],
                                    private="true")
        r1 = factories.Resource(package_id=dataset['id'])
        r2 = factories.Resource(package_id=dataset['id'])

        powerview = powerview_factories.PowerView(private='no',
                                                  resources=[r1['id'],
                                                             r2['id']])

        context = {'user': a_sysadmin['name'], 'model': model}
        nosetools.assert_true(
            helpers.call_auth('ckanext_powerview_resource_list',
                              context=context,
                              id=powerview['id']))
test_update.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_powerview_update(self):
        '''Updating with valid data_dict.'''
        sysadmin = Sysadmin()

        powerview_dict_create = factories.PowerView()

        powerview_dict_update = toolkit.get_action('powerview_update')(
            context={'user': sysadmin['name']},
            data_dict=powerview_dict_create.copy()
        )

        # last_modified has changed
        nosetools.assert_true(powerview_dict_create['last_modified'] is None)
        nosetools.assert_true(powerview_dict_update['last_modified']
                              is not None)
        # but it should be the only thing that changed
        powerview_dict_update['last_modified'] = None
        nosetools.assert_equal(powerview_dict_create, powerview_dict_update)
test_get.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_powerview_show_with_resources(self):
        '''Calling powerview show should return list of resource ids.'''
        sysadmin = Sysadmin()
        r1 = Resource()
        r2 = Resource()
        r3 = Resource()

        powerview_dict_create = factories.PowerView(resources=[r1['id'],
                                                               r2['id'],
                                                               r3['id']])

        powerview_dict_show = toolkit.get_action('powerview_show')(
            context={'user': sysadmin['name']},
            data_dict={'id': powerview_dict_create['id']}
        )

        nosetools.assert_equal(powerview_dict_create, powerview_dict_show)
        resource_list = powerview_dict_show['resources']
        nosetools.assert_equal(len(resource_list), 3)
        nosetools.assert_true(r1['id'] in resource_list)
        nosetools.assert_true(r2['id'] in resource_list)
        nosetools.assert_true(r3['id'] in resource_list)
test_get.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_powerview_list_offset_and_limit(self):
        '''
        Calling powerview_list with an offset and limit returns expected
        results.
        '''
        # make some powerviews
        for i in xrange(0, 20):
            factories.PowerView(title='powerview_{0}'.format(i + 1),
                                private=False)

        powerview_list = toolkit.get_action('powerview_list')(
            data_dict={
                'limit': 10,
                'offset': 10
            }
        )
        nosetools.assert_equal(len(powerview_list), 10)
        pv_ids = [pv['title'] for pv in powerview_list]
        for i in xrange(10, 20):
            nosetools.assert_true('powerview_{0}'.format(i + 1) in pv_ids)
test_get.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_powerview_list_private_powerview(self):
        '''
        Calling powerview_list by a normal user only returns public and
        authorized powerviews.
        '''
        user_one = User()
        user_two = User()

        p1 = factories.PowerView(user=user_one, private=False)
        p2 = factories.PowerView(user=user_one, private=True)

        context = {'user': user_two['name']}
        powerview_list = toolkit.get_action('powerview_list')(
            context=context,
            data_dict={'id': user_one['name']})

        nosetools.assert_equal(len(powerview_list), 1)
        nosetools.assert_true(p1 in powerview_list)
        nosetools.assert_true(p2 not in powerview_list)
test_get.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_powerview_list_private_powerview_authorized(self):
        '''
        Calling powerview_list by a normal user returns public and private
        powerviews if they are the creator.
        '''
        user_one = User()

        p1 = factories.PowerView(user=user_one, private=False)
        p2 = factories.PowerView(user=user_one, private=True)

        context = {'user': user_one['name']}
        powerview_list = toolkit.get_action('powerview_list')(
            context=context,
            data_dict={'id': user_one['name']})

        nosetools.assert_equal(len(powerview_list), 2)
        nosetools.assert_true(p1 in powerview_list)
        nosetools.assert_true(p2 in powerview_list)
test_get.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def test_powerview_list_user_powerviews(self):
        '''
        Calling powerview_list only returns powerviews for the passed user id.
        '''
        user_one = User()
        user_two = User()
        user_three = User()

        p1 = factories.PowerView(user=user_one, private=False)
        p2 = factories.PowerView(user=user_two, private=False)
        p3 = factories.PowerView(user=user_two, private=False)

        context = {'user': user_three['name']}
        powerview_list = toolkit.get_action('powerview_list')(
            context=context,
            data_dict={'id': user_two['name']})

        nosetools.assert_equal(len(powerview_list), 2)
        nosetools.assert_true(p1 not in powerview_list)
        nosetools.assert_true(p2 in powerview_list)
        nosetools.assert_true(p3 in powerview_list)
test_create.py 文件源码 项目:ckanext-powerview 作者: OCHA-DAP 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_powerview_create(self):
        '''Creating a powerview returns a dict with expected values'''
        sysadmin = Sysadmin()

        powerview_result = toolkit.get_action('powerview_create')(
            context={'user': sysadmin['name']},
            data_dict=self._make_create_data_dict()
        )

        nosetools.assert_true(isinstance(powerview_result, dict))
        nosetools.assert_true(powerview_result['title'] == 'Title')
        nosetools.assert_true(powerview_result['description'] ==
                              'My short description.')
        nosetools.assert_true(powerview_result['view_type'] == 'my-view-type')
        nosetools.assert_true(isinstance(powerview_result['config'], dict))
        nosetools.assert_true(powerview_result['private'])
        # created_by field auto-populated
        nosetools.assert_equal(powerview_result['created_by'], sysadmin['id'])
test_example_idatasetform.py 文件源码 项目:dati-ckan-docker 作者: italia 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def test_custom_search(self):
        helpers.call_action('package_create', name='test_package_a',
                            custom_text='z')
        helpers.call_action('package_create', name='test_package_b',
                            custom_text='y')

        response = self.app.get('/dataset')

        # change the sort by form to our custom_text ascending
        response.forms[1].fields['sort'][0].value = 'custom_text asc'
        response = response.forms[1].submit()
        # check that package_b appears before package a (y < z)
        a = response.body.index('test_package_a')
        b = response.body.index('test_package_b')
        nt.assert_true(b < a)

        response.forms[1].fields['sort'][0].value = 'custom_text desc'
        # check that package_a appears before package b (z is first in
        # descending order)
        response = response.forms[1].submit()
        a = response.body.index('test_package_a')
        b = response.body.index('test_package_b')
        nt.assert_true(a < b)
test_user.py 文件源码 项目:dati-ckan-docker 作者: italia 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def test_upgrade_from_sha_with_unicode_password(self):
        user = factories.User()
        password = u'testpassword\xc2\xa0'
        user_obj = model.User.by_name(user['name'])

        # setup our user with an old password hash
        old_hash = self._set_password(password)
        user_obj._password = old_hash
        user_obj.save()

        nt.assert_true(user_obj.validate_password(password))
        nt.assert_not_equals(old_hash, user_obj.password)
        nt.assert_true(pbkdf2_sha512.identify(user_obj.password))
        nt.assert_true(pbkdf2_sha512.verify(password, user_obj.password))

        # check that we now allow unicode characters
        nt.assert_false(pbkdf2_sha512.verify('testpassword',
                                             user_obj.password))


问题


面经


文章

微信
公众号

扫码关注公众号