示例#1
0
    def setup_class(cls):
        cls._original_config = config.copy()
        config['ckan.plugins'] = 'recline_preview'
        wsgiapp = make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        cls.p = previewplugin.ReclinePreview()

        # create test resource
        CreateTestData.create()

        context = {
            'model': model,
            'session': model.Session,
            'user': model.User.get('testsysadmin').name
        }

        cls.package = model.Package.get('annakarenina')
        cls.resource = logic.get_action('resource_show')(
            context, {
                'id': cls.package.resources[1].id
            })
        cls.resource['url'] = pylons.config.get('ckan.site_url',
                                                '//localhost:5000')
        cls.resource['format'] = 'csv'
        logic.action.update.resource_update(context, cls.resource)
示例#2
0
def load_config(config: Any, load_site_user: bool = True):
    conf = _get_config(config)
    assert 'ckan' not in dir()  # otherwise loggers would be disabled
    # We have now loaded the config. Now we can import ckan for the
    # first time.
    from ckan.config.environment import load_environment
    load_environment(conf)

    # Set this internal test request context with the configured environment so
    # it can be used when calling url_for from the CLI.
    global _cli_test_request_context

    app = make_app(conf)
    flask_app = app.apps['flask_app']._wsgi_app
    _cli_test_request_context = flask_app.test_request_context()

    registry = Registry()
    registry.prepare()

    site_user = None
    if model.user_table.exists() and load_site_user:
        site_user = logic.get_action('get_site_user')({
            'ignore_auth': True
        }, {})

    ## give routes enough information to run url_for
    parsed = urlparse(cast(str, conf.get('ckan.site_url', 'http://0.0.0.0')))
    request_config = routes.request_config()
    request_config.host = parsed.netloc + parsed.path
    request_config.protocol = parsed.scheme

    return site_user
示例#3
0
 def setup_class(cls):
     cls.base_csv_path = os.path.join(
         os.path.dirname(os.path.abspath(__file__)), 'csv')
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'iati_csv'
     wsgiapp = make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
示例#4
0
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id':
            resource.id,
            'force':
            True,
            'aliases':
            'books',
            'fields': [{
                'id': u'b\xfck',
                'type': 'text'
            }, {
                'id': 'author',
                'type': 'text'
            }, {
                'id': 'published'
            }, {
                'id': u'characters',
                u'type': u'_text'
            }, {
                'id': 'random_letters',
                'type': 'text[]'
            }],
            'records': [{
                u'b\xfck': 'annakarenina',
                'author': 'tolstoy',
                'published': '2005-03-01',
                'nested': ['b', {
                    'moo': 'moo'
                }],
                u'characters': [u'Princess Anna', u'Sergius'],
                'random_letters': ['a', 'e', 'x']
            }, {
                u'b\xfck': 'warandpeace',
                'author': 'tolstoy',
                'nested': {
                    'a': 'b'
                },
                'random_letters': []
            }]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create',
                           params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        engine = db.get_write_engine()
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        plugins.load('text_preview')
        cls.app = paste.fixture.TestApp(wsgiapp)

        cls.p = previewplugin.TextPreview()
        #cls.p.proxy_is_enabled = False

        # create test resource
        create_test_data.CreateTestData.create()

        context = {
            'model': model,
            'session': model.Session,
            'user': model.User.get('testsysadmin').name
        }

        cls.package = model.Package.get('annakarenina')
        cls.resource = logic.get_action('resource_show')(
            context, {
                'id': cls.package.resources[1].id
            })
        cls.resource['url'] = pylons.config.get('ckan.site_url',
                                                '//localhost:5000')
        logic.action.update.resource_update(context, cls.resource)
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     config.local_conf['ckan.plugins'] = 'todo'
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     CreateTestData.create()
     CreateTodoTestData.create()
示例#7
0
    def setup_class(cls):
        """Prepare the test"""

        # Setup a test app
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        # Load plugins
        p.load('doi')

        #  We need to actually create a dataset as DOI has foreign key constraint to dataset table
        ctd.CreateTestData.create()

        cls.context = {
            'model': ckan.model,
            'session': ckan.model.Session,
            'user': ckan.model.User.get('testsysadmin').name
        }

        cls.package = model.Package.get('annakarenina')
        cls.package_dict = toolkit.get_action('package_show')(
            cls.context, {
                'id': cls.package.id
            })

        # Add the author field
        cls.package_dict['author'] = 'Ben'
示例#8
0
 def test_routes_plugin_fired(self):
     local_config = appconfig('config:%s' % config['__file__'], relative_to=conf_dir)
     local_config.local_conf['ckan.plugins'] = 'routes_plugin'
     app = make_app(local_config.global_conf, **local_config.local_conf)
     routes_plugin = PluginGlobals.env().plugin_registry['RoutesPlugin'].__instance__
     assert routes_plugin.calls_made == ['before_map', 'after_map'], \
            routes_plugin.calls_made
示例#9
0
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        resource = model.Package.get('annakarenina').resources[0]
        cls.data = {
            'resource_id': resource.id,
            'aliases': 'books',
            'fields': [{'id': u'b\xfck', 'type': 'text'},
                       {'id': 'author', 'type': 'text'},
                       {'id': 'published'},
                       {'id': u'characters', u'type': u'_text'}],
            'records': [{u'b\xfck': 'annakarenina',
                        'author': 'tolstoy',
                        'published': '2005-03-01',
                        'nested': ['b', {'moo': 'moo'}],
                        u'characters': [u'Princess Anna', u'Sergius']},
                        {u'b\xfck': 'warandpeace', 'author': 'tolstoy',
                         'nested': {'a': 'b'}}]
        }
        postparams = '%s=1' % json.dumps(cls.data)
        auth = {'Authorization': str(cls.sysadmin_user.apikey)}
        res = cls.app.post('/api/action/datastore_create', params=postparams,
                           extra_environ=auth)
        res_dict = json.loads(res.body)
        assert res_dict['success'] is True

        engine = db._get_engine({
            'connection_url': config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例#10
0
 def test_routes_plugin_fired(self):
     config['ckan.plugins'] = 'routes_plugin'
     app = make_app(config['global_conf'], **config)
     routes_plugin = PluginGlobals.env_registry['pca'].plugin_registry[
         'RoutesPlugin'].__instance__
     assert routes_plugin.calls_made == ['before_map', 'after_map'], \
            routes_plugin.calls_made
示例#11
0
    def setup_class(cls):
        """Setup for all tests."""

        model.repo.rebuild_db()
        kata_model.setup()
        CreateTestData.create()

        cls.user_sysadmin = model.User.get('testsysadmin')  # Org admin
        cls.user_normal = model.User.get('tester')          # Org editor
        cls.user_anna = model.User.get('annafan')
        cls.user_joe = model.User.get('joeadmin')           # Org member

        wsgiapp = make_app(config['global_conf'], **config['app_conf'])
        cls.app = paste.fixture.TestApp(wsgiapp)

        # Set up API callers

        cls.api_user_normal = ckanapi.TestAppCKAN(cls.app, apikey=cls.user_normal.apikey)
        cls.api_user_sysadmin = ckanapi.TestAppCKAN(cls.app, apikey=cls.user_sysadmin.apikey)
        cls.api_user_anna = ckanapi.TestAppCKAN(cls.app, apikey=cls.user_anna.apikey)
        cls.api_user_joe = ckanapi.TestAppCKAN(cls.app, apikey=cls.user_joe.apikey)
        cls.api = ckanapi.TestAppCKAN(cls.app)

        cls.TEST_DATADICT = copy.deepcopy(TEST_DATADICT)

        try:
            output = cls.api_user_sysadmin.action.organization_create(**TEST_ORGANIZATION_COMMON)
            cls.TEST_DATADICT['owner_org'] = output.get('id')
        except AppError:
            print 'Failed to create a common organization. Perhaps it exists already.'
示例#12
0
    def setup_class(cls):
        cls.config_templates = config['ckan.legacy_templates']
        config['ckan.legacy_templates'] = 'false'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        create_test_data.CreateTestData.create()

        context = {
            'model': model,
            'session': model.Session,
            'user': model.User.get('testsysadmin').name
        }

        cls.package = model.Package.get('annakarenina')
        cls.resource_id = cls.package.resources[1].id
        cls.resource_view = {
            'resource_id': cls.resource_id,
            'view_type': u'image',
            'title': u'Image View',
            'description': u'A nice view',
            'image_url': 'test-image-view-url'
        }
        p.toolkit.get_action('resource_view_create')(context,
                                                     cls.resource_view)
示例#13
0
    def setup_class(cls):
        """Set up testing environment."""

        kata_model.setup()
        CreateTestData.create()

        wsgiapp = make_app(config['global_conf'], **config['app_conf'])
        cls.app = paste.fixture.TestApp(wsgiapp)
示例#14
0
 def test_resource_url(self):
     wsgiapp = middleware.make_app(config[u'global_conf'], **config)
     app = webtest.TestApp(wsgiapp)
     p.load(u'example_theme_v15_fanstatic')
     content = app.get(u'/en/base.html')
     assert u'example_theme.css' in content
     assert u'href="/data/fanstatic/example_theme' in content
     p.unload(u'example_theme_v15_fanstatic')
示例#15
0
    def setup_class(cls):
        cls._original_config = config.copy()
        config['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        # create test resource
        create_test_data.CreateTestData.create()
示例#16
0
文件: test_proxy.py 项目: 1sha1/ckan
    def setup_class(cls):
        cls._original_config = config.copy()
        config['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        # create test resource
        create_test_data.CreateTestData.create()
示例#17
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     config.local_conf['ckan.storage.directory'] = '/tmp/'
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     CreateTestData.create()
     model.Session.remove()
     user = model.User.by_name('tester')
     cls.extra_environ = {'Authorization': str(user.apikey)}
示例#18
0
 def test_routes_plugin_fired(self):
     local_config = appconfig('config:%s' % config['__file__'],
                              relative_to=conf_dir)
     local_config.local_conf['ckan.plugins'] = 'routes_plugin'
     app = make_app(local_config.global_conf, **local_config.local_conf)
     routes_plugin = PluginGlobals.env_registry['pca'].plugin_registry[
         'RoutesPlugin'].__instance__
     assert routes_plugin.calls_made == ['before_map', 'after_map'], \
            routes_plugin.calls_made
示例#19
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     for key in config.local_conf.keys():
         if key.startswith('ofs'):
             del config.local_conf[key]
     config.local_conf['ofs.impl'] = 'pairtree'
     config.local_conf['ckan.storage.bucket'] = 'ckantest'
     config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
示例#20
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'resource_proxy'
     wsgiapp = middleware.make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     create_test_data.CreateTestData.create()
     # Httpretty crashes with Solr on Python 2.6,
     # skip the tests
     if (sys.version_info[0] == 2 and sys.version_info[1] == 6):
         raise nose.SkipTest()
示例#21
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'resource_proxy'
     wsgiapp = middleware.make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     create_test_data.CreateTestData.create()
     # Httpretty crashes with Solr on Python 2.6,
     # skip the tests
     if (sys.version_info[0] == 2 and sys.version_info[1] == 6):
         raise nose.SkipTest()
示例#22
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     config.local_conf['ckan.plugins'] = 'wordpresser'
     config.local_conf['wordpresser.proxy_host'] \
                           = 'http://localhost:6969/'
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     env = {'HTTP_ACCEPT': 'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'}
     cls.app = paste.fixture.TestApp(wsgiapp, extra_environ=env)
     CreateTestData.create()
     runmockserver()
示例#23
0
文件: test_view.py 项目: Hoedic/ckan
 def setup_class(cls):
     if not p.plugin_loaded('recline_view'):
         p.load('recline_view')
     if not p.plugin_loaded('datastore'):
         p.load('datastore')
     app_config = config.copy()
     app_config['ckan.legacy_templates'] = 'false'
     app_config['ckan.plugins'] = 'recline_view datastore'
     app_config['ckan.views.default_views'] = 'recline_view'
     wsgiapp = middleware.make_app(config['global_conf'], **app_config)
     cls.app = paste.fixture.TestApp(wsgiapp)
 def setup_class(cls):
     if not p.plugin_loaded('recline_view'):
         p.load('recline_view')
     if not p.plugin_loaded('datastore'):
         p.load('datastore')
     app_config = config.copy()
     app_config['ckan.legacy_templates'] = 'false'
     app_config['ckan.plugins'] = 'recline_view datastore'
     app_config['ckan.views.default_views'] = 'recline_view'
     wsgiapp = middleware.make_app(config['global_conf'], **app_config)
     cls.app = paste.fixture.TestApp(wsgiapp)
示例#25
0
文件: ckan_setup.py 项目: mikkoi/ckan
def pytest_sessionstart(session):
    """Initialize CKAN environment.
    """
    conf = load_config(session.config.option.ckan_ini)
    # Set this internal test request context with the configured environment so
    # it can be used when calling url_for from the cli.
    global _tests_test_request_context

    app = make_app(conf.global_conf, **conf.local_conf)
    flask_app = app.apps['flask_app']._wsgi_app
    _tests_test_request_context = flask_app.test_request_context()
示例#26
0
    def __init__(self, conf=None):
        self.config = load_config(conf)

        # package_update needs a translator defined i.e. _()
        from paste.registry import Registry
        import pylons
        registry = Registry()
        registry.prepare()
        registry.register(pylons.translator, MockTranslator())

        self.app = make_app(self.config.global_conf, **self.config.local_conf)
示例#27
0
文件: test_view.py 项目: brune/ckan
    def setup_class(cls):
        cls.config_templates = config["ckan.legacy_templates"]
        config["ckan.legacy_templates"] = "false"
        wsgiapp = middleware.make_app(config["global_conf"], **config)
        plugins.load("text_view")
        cls.app = paste.fixture.TestApp(wsgiapp)
        cls.p = plugin.TextView()

        create_test_data.CreateTestData.create()

        cls.resource_view, cls.package, cls.resource_id = _create_test_view(cls.view_type)
示例#28
0
    def setup_class(cls):
        cls.config_templates = config['ckan.legacy_templates']
        config['ckan.legacy_templates'] = 'false'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        plugins.load('text_view')
        cls.app = paste.fixture.TestApp(wsgiapp)
        cls.p = plugin.TextView()

        create_test_data.CreateTestData.create()

        cls.resource_view, cls.package, cls.resource_id = \
            _create_test_view(cls.view_type)
示例#29
0
    def setup_class(cls):
        config = appconfig('config:test.ini', relative_to=conf_dir)
        for key in config.local_conf.keys():
            if key.startswith('ofs'):
                del config.local_conf[key]
        config.local_conf['ofs.impl'] = 'pairtree'
        config.local_conf['ckan.storage.bucket'] = 'ckantest'
        config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'

        create_pairtree_marker( config.local_conf['ofs.storage_dir'] )
        wsgiapp = make_app(config.global_conf, **config.local_conf)
        cls.app = paste.fixture.TestApp(wsgiapp)
示例#30
0
    def setup_class(cls):
        cls.config_templates = config['ckan.legacy_templates']
        config['ckan.legacy_templates'] = 'false'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        plugins.load('text_view')
        cls.app = paste.fixture.TestApp(wsgiapp)
        cls.p = plugin.TextView()

        create_test_data.CreateTestData.create()

        cls.resource_view, cls.package, cls.resource_id = \
            _create_test_view(cls.view_type)
示例#31
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例#32
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get('testsysadmin')
        cls.normal_user = model.User.get('annafan')
        engine = db._get_engine(
            {'connection_url': pylons.config['ckan.datastore.write_url']})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例#33
0
    def setup_class(cls):

        wsgiapp = middleware.make_app(config["global_conf"], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load("datastore")
        ctd.CreateTestData.create()
        cls.sysadmin_user = model.User.get("testsysadmin")
        cls.normal_user = model.User.get("annafan")
        engine = db._get_engine({"connection_url": pylons.config["ckan.datastore.write_url"]})
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
        set_url_type(model.Package.get("annakarenina").resources, cls.sysadmin_user)
示例#34
0
 def setup_class(cls):
     wsgiapp = middleware.make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load('datastore')
     p.load('datapusher')
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get('testsysadmin')
     cls.normal_user = model.User.get('annafan')
     engine = db.get_write_engine()
     cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
     set_url_type(
         model.Package.get('annakarenina').resources, cls.sysadmin_user)
示例#35
0
    def setup_class(cls):
        InitDB("initdb").run([])  # set up database tables

        config = appconfig('config:test.ini', relative_to=conf_dir)
        config.local_conf['ckan.plugins'] = 'googleanalytics'
        config.local_conf['googleanalytics.id'] = 'UA-borf-1'
        config.local_conf['googleanalytics.show_downloads'] = 'true'
        cls.config = config.local_conf
        wsgiapp = make_app(config.global_conf, **config.local_conf)
        env = {'HTTP_ACCEPT': ('text/html;q=0.9,text/plain;'
                               'q=0.8,image/png,*/*;q=0.5')}
        cls.app = paste.fixture.TestApp(wsgiapp, extra_environ=env)
        CreateTestData.create()
        runmockserver()
示例#36
0
    def setup_class(cls):
        cls._original_config = config.copy()
        config['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        if not cls.serving:
            file_server.serve()
            cls.serving = True
            # gets shutdown when nose finishes all tests,
            # so don't restart ever

        # create test resource
        create_test_data.CreateTestData.create()
示例#37
0
 def setup_class(cls):
     wsgiapp = middleware.make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     if not tests.is_datastore_supported():
         raise nose.SkipTest("Datastore not supported")
     p.load('datastore')
     p.load('datapusher')
     ctd.CreateTestData.create()
     cls.sysadmin_user = model.User.get('testsysadmin')
     cls.normal_user = model.User.get('annafan')
     engine = db.get_write_engine()
     cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
     set_url_type(
         model.Package.get('annakarenina').resources, cls.sysadmin_user)
示例#38
0
文件: test_proxy.py 项目: ArnY/ckan
    def setup_class(cls):
        cls._original_config = config.copy()
        config['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        if not cls.serving:
            file_server.serve()
            cls.serving = True
            # gets shutdown when nose finishes all tests,
            # so don't restart ever

        # create test resource
        create_test_data.CreateTestData.create()
示例#39
0
    def setup_class(cls):
        config = appconfig('config:test.ini', relative_to=tests.conf_dir)
        config.local_conf['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config.global_conf, **config.local_conf)
        cls.app = paste.fixture.TestApp(wsgiapp)

        if not cls.serving:
            file_server.serve()
            cls.serving = True
            # gets shutdown when nose finishes all tests,
            # so don't restart ever

        # create test resource
        create_test_data.CreateTestData.create()
示例#40
0
    def setup_class(cls):
        cls._original_config = config.copy()
        for key in config.keys():
            if key.startswith('ofs'):
                del config[key]
        config['ofs.impl'] = 'pairtree'
        config['ckan.storage.bucket'] = 'ckantest'
        config['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'

        create_pairtree_marker( config['ofs.storage_dir'] )
        wsgiapp = make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        CreateTestData.create_test_user()
示例#41
0
    def setup_class(cls):
        config = appconfig('config:test.ini', relative_to=tests.conf_dir)
        config.local_conf['ckan.plugins'] = 'resource_proxy'
        wsgiapp = middleware.make_app(config.global_conf, **config.local_conf)
        cls.app = paste.fixture.TestApp(wsgiapp)

        if not cls.serving:
            file_server.serve()
            cls.serving = True
            # gets shutdown when nose finishes all tests,
            # so don't restart ever

        # create test resource
        create_test_data.CreateTestData.create()
示例#42
0
    def get_app(cls):
        '''
        Alternative method for creating a test app. Not needed if inheriting from WsgiAppCase
        '''
        if not 'ckan.plugins' in config:
            config['ckan.plugins'] = 'hdx_package'
        else:
            config['ckan.plugins'] += 'hdx_package'
        app = make_app(config['global_conf'], **config)
        app = webtest.TestApp(app)
        
#       p.load('metadata_fields')
        
        cls.app = app;
示例#43
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     for key in config.local_conf.keys():
         if key.startswith('ofs'):
             del config.local_conf[key]
     config.local_conf['ckan.storage.bucket'] = 'ckantest'
     config.local_conf['ofs.impl'] = 'pairtree'
     config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     CreateTestData.create()
     model.Session.remove()
     user = model.User.by_name('tester')
     cls.extra_environ = {'Authorization': str(user.apikey)}
示例#44
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     for key in config.local_conf.keys():
         if key.startswith('ofs'):
             del config.local_conf[key]
     config.local_conf['ckan.storage.bucket'] = 'ckantest'
     config.local_conf['ofs.impl'] = 'pairtree'
     config.local_conf['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
     create_pairtree_marker( config.local_conf['ofs.storage_dir'] )
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     CreateTestData.create()
     model.Session.remove()
     user = model.User.by_name('tester')
     cls.extra_environ = {'Authorization': str(user.apikey)}
示例#45
0
 def setup_class(cls):
     cls._original_config = config.copy()
     for key in config.keys():
         if key.startswith('ofs'):
             del config[key]
     config['ckan.storage.bucket'] = 'ckantest'
     config['ofs.impl'] = 'pairtree'
     config['ofs.storage_dir'] = '/tmp/ckan-test-ckanext-storage'
     create_pairtree_marker( config['ofs.storage_dir'] )
     wsgiapp = make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     CreateTestData.create()
     model.Session.remove()
     user = model.User.by_name('tester')
     cls.extra_environ = {'Authorization': str(user.apikey)}
示例#46
0
    def setup_class(cls):
        kata_model.setup()
        users = [
            {'name': 'test_sysadmin',
             'sysadmin': True,
             'apikey': 'test_sysadmin',
             'password': '******'},
            {'name': 'test_user',
             'sysadmin': False,
             'apikey': 'test_user',
             'password': '******'},
            {'name': 'test_user2',
             'sysadmin': False,
             'apikey': 'test_user2',
             'password': '******'}
        ]
        CreateTestData.create_users(users)
        cls.test_user = user_model.User.get('test_user')
        cls.test_user2 = user_model.User.get('test_user2')
        cls.test_sysadmin = user_model.User.get('test_sysadmin')

        wsgiapp = make_app(config['global_conf'], **config['app_conf'])
        cls.app = paste.fixture.TestApp(wsgiapp)

        # Set up API callers

        cls.api_test_user = ckanapi.TestAppCKAN(cls.app, apikey=cls.test_user.apikey)
        cls.api_test_user2 = ckanapi.TestAppCKAN(cls.app, apikey=cls.test_user2.apikey)
        cls.api_test_sysadmin = ckanapi.TestAppCKAN(cls.app, apikey=cls.test_sysadmin.apikey)
        cls.api = ckanapi.TestAppCKAN(cls.app)

        org_dict = {'name': 'test_organisation', 'title': 'Test Organisation'}
        cls.api_test_sysadmin.action.organization_create(**org_dict)

        group_dict = {'name': 'test_group', 'title': 'Test Group'}
        cls.api_test_sysadmin.action.group_create(**group_dict)

        user_dict = {'id': 'test_organisation', 'username': '******', 'role': 'admin'}
        cls.api_test_sysadmin.action.organization_member_create(**user_dict)

        user_dict = {'id': 'test_group', 'username': '******', 'role': 'admin'}
        cls.api_test_sysadmin.action.group_member_create(**user_dict)

        cls.TEST_DATADICT = copy.deepcopy(TEST_DATADICT)
        cls.package_id = u'urn-nbn-fi-csc-kata20140728095757755621'
        cls.TEST_DATADICT['owner_org'] = 'test_organisation'
        cls.TEST_DATADICT['id'] = cls.package_id
        cls.api_test_user.action.package_create(**cls.TEST_DATADICT)
示例#47
0
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        p.load('datapusher')
        p.load('test_datapusher_plugin')

        resource = factories.Resource(url_type='datastore')
        cls.dataset = factories.Dataset(resources=[resource])

        cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True)
        cls.normal_user = factories.User(name='annafan')
        engine = db.get_write_engine()
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例#48
0
    def setup_class(cls):
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")
        p.load('datastore')
        p.load('datapusher')
        p.load('test_datapusher_plugin')

        resource = factories.Resource(url_type='datastore')
        cls.dataset = factories.Dataset(resources=[resource])

        cls.sysadmin_user = factories.User(name='testsysadmin', sysadmin=True)
        cls.normal_user = factories.User(name='annafan')
        engine = db.get_write_engine()
        cls.Session = orm.scoped_session(orm.sessionmaker(bind=engine))
示例#49
0
    def setup_class(cls):
        InitDB("initdb").run([])  # set up database tables

        config = appconfig('config:test.ini', relative_to=conf_dir)
        config.local_conf['ckan.plugins'] = 'googleanalytics'
        config.local_conf['googleanalytics.id'] = 'UA-borf-1'
        config.local_conf['googleanalytics.show_downloads'] = 'true'
        cls.config = config.local_conf
        wsgiapp = make_app(config.global_conf, **config.local_conf)
        env = {
            'HTTP_ACCEPT': ('text/html;q=0.9,text/plain;'
                            'q=0.8,image/png,*/*;q=0.5')
        }
        cls.app = paste.fixture.TestApp(wsgiapp, extra_environ=env)
        CreateTestData.create()
        runmockserver()
示例#50
0
    def setup_class(cls):
        config = appconfig("config:test.ini", relative_to=conf_dir)
        config.local_conf["ckan.plugins"] = "junar"
        config.local_conf["junar_api_key"] = JUNAR_API_KEY
        config.local_conf["junar_api_url"] = "http://api.staging.junar.com"
        config.local_conf["junar_base_url"] = "http://staging.junar.com"
        wsgiapp = make_app(config.global_conf, **config.local_conf)
        cls.app = paste.fixture.TestApp(wsgiapp)
        with Stub() as DataStream:
            DataStream.guid >> "the-precious-guid"

        with Stub() as Junar:
            from junar_api import junar_api

            junar_api_client = junar_api.Junar(JUNAR_API_KEY, base_uri="http://api.staging.junar.com")

            junar_api_client.publish(kind_of(dict)) >> DataStream
示例#51
0
    def setup_class(cls):
        InitDB("initdb").run([])  # set up database tables

        config = appconfig("config:test.ini", relative_to=conf_dir)
        config.local_conf["ckan.plugins"] = "googleanalytics"
        config.local_conf["googleanalytics.username"] = "******"
        config.local_conf["googleanalytics.password"] = "******"
        config.local_conf["googleanalytics.id"] = "UA-borf-1"
        config.local_conf["googleanalytics.show_downloads"] = "true"
        cls.config = config.local_conf
        wsgiapp = make_app(config.global_conf, **config.local_conf)
        env = {
            "HTTP_ACCEPT": ("text/html;q=0.9,text/plain;"
                            "q=0.8,image/png,*/*;q=0.5")
        }
        cls.app = paste.fixture.TestApp(wsgiapp, extra_environ=env)
        CreateTestData.create()
        runmockserver()
示例#52
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     # setup test data including testsysadmin user
     CreateTestData.create()
     # Creating a couple of authorization groups, which are enough to break
     # some things just by their existence
     for ag_name in [u'anauthzgroup', u'anotherauthzgroup']:
         ag=model.AuthorizationGroup.by_name(ag_name) 
         if not ag: #may already exist, if not create
             ag=model.AuthorizationGroup(name=ag_name)
             model.Session.add(ag)
     model.Session.commit()
     #they are especially dangerous if they have a role on the System
     ag = model.AuthorizationGroup.by_name(u'anauthzgroup')
     model.add_authorization_group_to_role(ag, u'editor', model.System())
     model.Session.commit()
示例#53
0
def pytest_sessionstart(session):
    """Initialize CKAN environment.
    """
    conf = load_config(session.config.option.ckan_ini)
    # Set this internal test request context with the configured environment so
    # it can be used when calling url_for from the cli.
    global _tests_test_request_context

    app = make_app(conf)
    try:
        flask_app = app.apps['flask_app']._wsgi_app
    except AttributeError:
        flask_app = app._wsgi_app
    _tests_test_request_context = flask_app.test_request_context()

    # Create the snapshot of the initial configuration
    global _config
    _config = config.copy()
    def setup_class(cls):
        """Prepare the test"""
        # We need datastore for these tests.
        if not tests.is_datastore_supported():
            raise nose.SkipTest("Datastore not supported")

        # Setup a test app
        wsgiapp = middleware.make_app(config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
        ctd.CreateTestData.create()
        cls.context = {'model': ckan.model,
                       'session': ckan.model.Session,
                       'user': ckan.model.User.get('testsysadmin').name}
        cls.engine = create_engine(config['ckan.datastore.write_url'])

        # Load plugins
        p.load('tiledmap')
        p.load('datastore')
    def setup_class(cls):
        cls._original_config = config.copy()
        config["ckan.plugins"] = "recline_preview"
        wsgiapp = make_app(config["global_conf"], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)

        cls.p = previewplugin.ReclinePreview()

        # create test resource
        CreateTestData.create()

        context = {"model": model, "session": model.Session, "user": model.User.get("testsysadmin").name}

        cls.package = model.Package.get("annakarenina")
        cls.resource = logic.get_action("resource_show")(context, {"id": cls.package.resources[1].id})
        cls.resource["url"] = pylons.config.get("ckan.site_url", "//localhost:5000")
        cls.resource["format"] = "csv"
        logic.action.update.resource_update(context, cls.resource)
示例#56
0
def load_config(config, load_site_user=True):
    conf = _get_config(config)
    assert 'ckan' not in dir()  # otherwise loggers would be disabled
    # We have now loaded the config. Now we can import ckan for the
    # first time.
    from ckan.config.environment import load_environment
    load_environment(conf)

    # Set this internal test request context with the configured environment so
    # it can be used when calling url_for from the CLI.
    global _cli_test_request_context

    app = make_app(conf)
    flask_app = app.apps['flask_app']._wsgi_app
    _cli_test_request_context = flask_app.test_request_context()

    registry = Registry()
    registry.prepare()
    import pylons
    registry.register(pylons.translator, MockTranslator())

    site_user = None
    if model.user_table.exists() and load_site_user:
        # If the DB has already been initialized, create and register
        # a pylons context object, and add the site user to it, so the
        # auth works as in a normal web request
        c = pylons.util.AttribSafeContextObj()

        registry.register(pylons.c, c)

        site_user = logic.get_action('get_site_user')({
            'ignore_auth': True
        }, {})

        pylons.c.user = site_user['name']
        pylons.c.userobj = model.User.get(site_user['name'])

    ## give routes enough information to run url_for
    parsed = urlparse(conf.get('ckan.site_url', 'http://0.0.0.0'))
    request_config = routes.request_config()
    request_config.host = parsed.netloc + parsed.path
    request_config.protocol = parsed.scheme

    return site_user
示例#57
0
    def setup_class(cls):
        """Set up testing environment."""

        model.repo.rebuild_db()
        kata_model.setup()
        CreateTestData.create()
        comments_model.init_tables()

        wsgiapp = make_app(config['global_conf'], **config['app_conf'])
        cls.app = paste.fixture.TestApp(wsgiapp)

        # The Pylons globals are not available outside a request. This is a hack to provide context object.
        c = AttribSafeContextObj()
        py_obj = PylonsContext()
        py_obj.tmpl_context = c
        pylons.tmpl_context._push_object(c)

        # The lxml's HTML parser allows quite much errors so it is not really a good validation of the rendered pages.
        cls.html_parser = etree.HTMLParser()
示例#58
0
 def setup_class(cls):
     config = appconfig('config:test.ini', relative_to=conf_dir)
     config.local_conf['ckan.storage.bucket'] = 'ckantest'
     config.local_conf['ofs.impl'] = 'google'
     if 'ofs.gs_secret_access_key' not in config.local_conf:
         raise Exception('You will need to configure access to google storage to run this test')
     # You will need these configured in your
     # config.local_conf['ofs.gs_access_key_id'] = 'GOOGCABCDASDASD'
     # config.local_conf['ofs.gs_secret_access_key'] = '134zsdfjkw4234addad'
     # need to ensure not configured for local as breaks google setup
     # (and cannot delete all ofs keys as need the gs access codes)
     if 'ofs.storage_dir' in config.local_conf:
         del config.local_conf['ofs.storage_dir']
     wsgiapp = make_app(config.global_conf, **config.local_conf)
     cls.app = paste.fixture.TestApp(wsgiapp)
     # setup test data including testsysadmin user
     CreateTestData.create()
     model.Session.remove()
     user = model.User.by_name('tester')
     cls.extra_environ = {'Authorization': str(user.apikey)}