示例#1
0
    def setup_class(cls):
        #        TestAuth.setup_class()
        CreateTestData.create_group_hierarchy_test_data()

        cls.apikeys = {}
        for user in model.Session.query(model.User):
            cls.apikeys[user.name] = str(user.apikey)

        cls.sysadmin = get_action('get_site_user')({
            'model': model,
            'ignore_auth': True
        }, {})

        cls._original_config = config.copy()

        config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'

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

        CreateTestData.create_arbitrary(package_dicts=[{
            'name':
            'adataset',
            'groups': ['national-health-service']
        }],
                                        extra_user_names=['john'])
示例#2
0
    def ckan_config(request, monkeypatch):
        """Allows to override the configuration object used by tests

        Takes into account config patches introduced by the ``ckan_config``
        mark.

        If you just want to set one or more configuration options for the
        scope of a test (or a test class), use the ``ckan_config`` mark::

            @pytest.mark.ckan_config('ckan.auth.create_unowned_dataset', True)
            def test_auth_create_unowned_dataset():

                # ...

        To use the custom config inside a test, apply the
        ``ckan_config`` mark to it and inject the ``ckan_config`` fixture:

        .. literalinclude:: /../ckan/tests/pytest_ckan/test_fixtures.py
           :start-after: # START-CONFIG-OVERRIDE
           :end-before: # END-CONFIG-OVERRIDE

        If the change only needs to be applied locally, use the
        ``monkeypatch`` fixture

        .. literalinclude:: /../ckan/tests/test_common.py
           :start-after: # START-CONFIG-OVERRIDE
           :end-before: # END-CONFIG-OVERRIDE

        """
        _original = config.copy()
        for mark in request.node.iter_markers(u"ckan_config"):
            monkeypatch.setitem(config, *mark.args)
        yield config
        config.clear()
        config.update(_original)
示例#3
0
 def setup_class(cls):
     cls._original_config = config.copy()
     cls.app = _get_test_app()
     if not p.plugin_loaded('resource_proxy'):
         p.load('resource_proxy')
     config['ckan.plugins'] = 'resource_proxy'
     create_test_data.CreateTestData.create()
示例#4
0
    def setup_class(cls):
        admin_api = get_action('get_site_user')({
            'model': model,
            'ignore_auth': True
        }, {})['apikey']
        ## This is a mutable dict on the class level so tests can
        ## add apikeys as they go along
        cls.apikeys = {'sysadmin': str(admin_api), 'random_key': 'moo'}

        cls._original_config = config.copy()

        config['ckan.auth.anon_create_dataset'] = False
        config['ckan.auth.create_dataset_if_not_in_organization'] = False
        config['ckan.auth.user_create_groups'] = False
        config['ckan.auth.user_create_organizations'] = False
        config['ckan.auth.user_delete_groups'] = False
        config['ckan.auth.user_delete_organizations'] = False
        config['ckan.auth.create_unowned_dataset'] = False
        config['ckan.auth.create_user_via_api'] = False
        config['ckan.auth.create_user_via_web'] = True
        config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'

        wsgiapp = ckan.config.middleware.make_app(config['global_conf'],
                                                  **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
示例#5
0
 def setup_class(cls):
     cls._original_config = config.copy()
     cls.app = _get_test_app()
     if not p.plugin_loaded('resource_proxy'):
         p.load('resource_proxy')
     config['ckan.plugins'] = 'resource_proxy'
     create_test_data.CreateTestData.create()
示例#6
0
    def setup_class(cls):
        cls._original_config = config.copy()

        # Don't send email notifications for activities older than 1
        # microsecond.
        config['ckan.email_notifications_since'] = '.000001'

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

        mock_mail_server.SmtpServerHarness.setup_class()
        pylons_controller.PylonsTestCase.setup_class()
        tests.CreateTestData.create()

        joeadmin = model.User.get('joeadmin')
        cls.joeadmin = {
            'id': joeadmin.id,
            'apikey': joeadmin.apikey,
        }
        testsysadmin = model.User.get('testsysadmin')
        cls.testsysadmin = {
            'id': testsysadmin.id,
            'apikey': testsysadmin.apikey,
        }
示例#7
0
 def setup_class(cls):
     CreateTestData.create()
     cls._original_config = config.copy()
     wsgiapp = ckan.config.middleware.make_app(config['global_conf'],
                                               **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     cls.sysadmin_user = model.User.get('testsysadmin')
     PylonsTestCase.setup_class()
示例#8
0
 def setup_class(cls):
     CreateTestData.create()
     cls._original_config = config.copy()
     wsgiapp = ckan.config.middleware.make_app(
         config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
     cls.sysadmin_user = model.User.get('testsysadmin')
     PylonsTestCase.setup_class()
示例#9
0
 def changed_config(key, value):
     _original_config = config.copy()
     config[key] = value
     try:
         yield
     finally:
         config.clear()
         config.update(_original_config)
示例#10
0
 def setup_class(cls):
     CreateTestData.create()
     cls._original_config = config.copy()
     config['ckan.auth.create_user_via_web'] = True
     wsgiapp = ckan.config.middleware.make_app(
         config['global_conf'], **config)
     cls.app = helpers._get_test_app()
     cls.sysadmin_user = model.User.get('testsysadmin')
     PylonsTestCase.setup_class()
示例#11
0
 def setup_class(cls):
     cls.app = _get_test_app()
     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'
示例#12
0
 def setup_class(cls):
     cls.app = _get_test_app()
     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'
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
文件: helpers.py 项目: AQUACROSS/ckan
        def wrapper(*args, **kwargs):
            _original_config = config.copy()
            config[key] = value

            try:
                return_value = func(*args, **kwargs)
            finally:
                config.clear()
                config.update(_original_config)

            return return_value
示例#16
0
        def wrapper(*args, **kwargs):
            _original_config = config.copy()
            config[key] = value

            try:
                return_value = func(*args, **kwargs)
            finally:
                config.clear()
                config.update(_original_config)

            return return_value
示例#17
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()
示例#18
0
    def setup_class(cls):
#        TestAuth.setup_class()
        CreateTestData.create_group_hierarchy_test_data()

        cls.apikeys = {}
        for user in model.Session.query(model.User):
            cls.apikeys[user.name] = str(user.apikey)

        cls._original_config = config.copy()

        config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'

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

        CreateTestData.create_arbitrary(
            package_dicts= [{'name': 'adataset',
                             'groups': ['national-health-service']}],
            extra_user_names=['john'])
示例#19
0
def changed_config(key, value):
    '''
    Context manager for temporarily changing a config value.

    Allows you to temporarily change the value of a CKAN configuration
    option. The original value is restored once the context manager is
    left.

    Usage::

        with changed_config(u'ckan.site_title', u'My Test CKAN'):
            assert config[u'ckan.site_title'] == u'My Test CKAN'

    .. seealso:: The decorator :py:func:`change_config`
    '''
    _original_config = config.copy()
    config[key] = value
    try:
        yield
    finally:
        config.clear()
        config.update(_original_config)
示例#20
0
def changed_config(key, value):
    """
    Context manager for temporarily changing a config value.

    Allows you to temporarily change the value of a CKAN configuration
    option. The original value is restored once the context manager is
    left.

    Usage::

        with changed_config(u'ckan.site_title', u'My Test CKAN'):
            assert config[u'ckan.site_title'] == u'My Test CKAN'

    .. seealso:: The decorator :py:func:`change_config`
    """
    _original_config = config.copy()
    config[key] = value
    try:
        yield
    finally:
        config.clear()
        config.update(_original_config)
示例#21
0
    def setup_class(cls):
        cls._original_config = config.copy()

        # Disable the email notifications feature.
        config['ckan.activity_streams_email_notifications'] = False

        wsgiapp = ckan.config.middleware.make_app(config['global_conf'],
                **config)
        cls.app = helpers._get_test_app()

        mock_mail_server.SmtpServerHarness.setup_class()
        pylons_controller.PylonsTestCase.setup_class()
        tests.CreateTestData.create()

        joeadmin = model.User.get('joeadmin')
        cls.joeadmin = {'id': joeadmin.id,
                'apikey': joeadmin.apikey,
                }
        testsysadmin = model.User.get('testsysadmin')
        cls.testsysadmin = {'id': testsysadmin.id,
                'apikey': testsysadmin.apikey,
                }
示例#22
0
    def setup_class(cls):
        cls._original_config = config.copy()

        # Disable the email notifications feature.
        config['ckan.activity_streams_email_notifications'] = False

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

        mock_mail_server.SmtpServerHarness.setup_class()
        pylons_controller.PylonsTestCase.setup_class()
        tests.CreateTestData.create()

        joeadmin = model.User.get('joeadmin')
        cls.joeadmin = {'id': joeadmin.id,
                'apikey': joeadmin.apikey,
                }
        testsysadmin = model.User.get('testsysadmin')
        cls.testsysadmin = {'id': testsysadmin.id,
                'apikey': testsysadmin.apikey,
                }
示例#23
0
    def setup_class(cls):
        cls._original_config = config.copy()

        # Don't send email notifications for activities older than 1
        # microsecond.
        config['ckan.email_notifications_since'] = '.000001'

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

        mock_mail_server.SmtpServerHarness.setup_class()
        pylons_controller.PylonsTestCase.setup_class()
        tests.CreateTestData.create()

        joeadmin = model.User.get('joeadmin')
        cls.joeadmin = {'id': joeadmin.id,
                'apikey': joeadmin.apikey,
                }
        testsysadmin = model.User.get('testsysadmin')
        cls.testsysadmin = {'id': testsysadmin.id,
                'apikey': testsysadmin.apikey,
                }
示例#24
0
    def setup_class(cls):
        admin_api = get_action('get_site_user')(
            {'model': model, 'ignore_auth': True}, {})['apikey']
        ## This is a mutable dict on the class level so tests can
        ## add apikeys as they go along
        cls.apikeys = {'sysadmin': str(admin_api), 'random_key': 'moo'}

        cls._original_config = config.copy()

        config['ckan.auth.anon_create_dataset'] = False
        config['ckan.auth.create_dataset_if_not_in_organization'] = False
        config['ckan.auth.user_create_groups'] = False
        config['ckan.auth.user_create_organizations'] = False
        config['ckan.auth.user_delete_groups'] = False
        config['ckan.auth.user_delete_organizations'] = False
        config['ckan.auth.create_unowned_dataset'] = False
        config['ckan.auth.create_user_via_api'] = False
        config['ckan.auth.create_user_via_web'] = True
        config['ckan.auth.roles_that_cascade_to_sub_groups'] = 'admin'

        wsgiapp = ckan.config.middleware.make_app(
            config['global_conf'], **config)
        cls.app = paste.fixture.TestApp(wsgiapp)
 def setup_class(cls):
     cls.original_config = config.copy()
     cls.app = helpers._get_test_app()
     plugins.load('example_idatasetform')
 def setup_class(cls):
     cls.original_config = config.copy()
示例#27
0
 def setup_class(cls):
     cls.original_config = config.copy()
     config['ckan.plugins'] = 'example_idatasetform'
示例#28
0
 def setup(self):
     self._original_config = ckan_config.copy()
示例#29
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()
示例#30
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'stats'
     wsgiapp = make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
示例#31
0
# -*- coding: utf-8 -*-

import ckan.plugins as plugins
from ckan.config.middleware import make_app
from ckan.cli import load_config
from ckan.common import config

# This is a test Flask request context to be used internally.
# Do not use it!
_tests_test_request_context = None

# Initial config snapshot that is used to restore config object before each
# test. This allows us to keep tests independent while we are using global
# config object.
_config = config.copy()


def pytest_addoption(parser):
    """Allow using custom config file during tests.

    Catch the exception raised by pytest if  the ``--ckan-ini`` option was
    already added by the external pytest-ckan package
    """
    try:
        parser.addoption(u"--ckan-ini", action=u"store")
    except ValueError as e:
        if str(e) == 'option names {\'--ckan-ini\'} already added':
            pass
        else:
            raise
示例#32
0
 def setup_class(cls):
     cls.original_config = config.copy()
     if not ckan.plugins.plugin_loaded('string_to_location'):
         ckan.plugins.load('string_to_location')
示例#33
0
 def setup(self):
     self._original_config = ckan_config.copy()
示例#34
0
 def setup_class(cls):
     cls.original_config = config.copy()
     cls.app = helpers._get_test_app()
     plugins.load('example_idatasetform')
示例#35
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()
示例#36
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'stats'
     cls.app = _get_test_app()
示例#37
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'resource_proxy'
     cls.app = helpers._get_test_app()
     create_test_data.CreateTestData.create()
 def setup_class(cls):
     cls.original_config = config.copy()
     plugins.load('example_idatasetform_v4')
示例#39
0
 def setup_class(cls):
     cls.original_config = config.copy()
示例#40
0
 def setup_class(cls):
     cls._original_config = config.copy()
     config['ckan.plugins'] = 'stats'
     wsgiapp = make_app(config['global_conf'], **config)
     cls.app = paste.fixture.TestApp(wsgiapp)
示例#41
0
 def setup_class(cls):
     cls.original_config = config.copy()
     config["ckan.plugins"] = "example_idatasetform"
 def setup_class(cls):
     cls.original_config = config.copy()
     config['ckan.plugins'] = 'example_idatasetform'
示例#43
0
 def setup_class(cls):
     cls.original_config = config.copy()
     plugins.load('example_idatasetform_v4')