Пример #1
0
    def teardown_class(cls):
        plugins.unload('example_idatasetform_v4')
        helpers.reset_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Пример #2
0
    def teardown_class(cls):
        helpers.reset_db()
        model.repo.rebuild_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Пример #3
0
def pytest_runtest_setup(item):
    """Automatically apply `ckan_config` fixture if test has `ckan_config`
    mark.

    `ckan_config` mark itself does nothing(as any mark). All actual
    config changes performed inside `ckan_config` fixture. So let's
    implicitly use `ckan_config` fixture inside any test that patches
    config object. This will save us from adding
    `@mark.usefixtures("ckan_config")` every time.

    """
    # Restore configuration from the snapshot, removing all customization that
    # were done during previous tests.  Note, it is not related to
    # `ckan_config` fixture, which restores config object itself. This is
    # needed because such modules as `ckan.lib.app_globals` can mutate global
    # config object. Potentially can be removed, when the logic behind
    # `app_globals` stops modifying global config object.
    config.clear()
    config.update(_config)

    custom_config = [
        mark.args for mark in item.iter_markers(name=u"ckan_config")
    ]

    if custom_config:
        item.fixturenames.append(u"ckan_config")
Пример #4
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 = copy.deepcopy(config)
    for mark in request.node.iter_markers(u"ckan_config"):
        monkeypatch.setitem(config, *mark.args)
    yield config
    config.clear()
    config.update(_original)
Пример #5
0
    def teardown_class(cls):
        helpers.reset_db()
        model.repo.rebuild_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Пример #6
0
    def teardown_class(cls):
        plugins.unload('example_idatasetform')
        helpers.reset_db()
        ckan.lib.search.clear_all()

        config.clear()
        config.update(cls.original_config)
Пример #7
0
 def teardown_class(cls):
     import ckan.plugins as p
     for plugin in reversed(getattr(cls, '_load_plugins', [])):
         p.unload(plugin)
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Пример #8
0
 def changed_config(key, value):
     _original_config = config.copy()
     config[key] = value
     try:
         yield
     finally:
         config.clear()
         config.update(_original_config)
Пример #9
0
 def teardown_class(cls):
     import ckan.plugins as p
     for plugin in reversed(getattr(cls, '_load_plugins', [])):
         p.unload(plugin)
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Пример #10
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
Пример #11
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
Пример #12
0
    def test_js_included(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.view',
                            id=self.package.name, resource_id=self.resource_id,
                            view_id=self.resource_view['id'])
        result = app.get(url)
        assert (('text_view.js' in result.body) or  # Source file
                ('textview.js' in result.body))     # Compiled file
        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Пример #13
0
    def test_js_included(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.view',
                            id=self.package.name, resource_id=self.resource_id,
                            view_id=self.resource_view['id'])
        result = app.get(url)
        assert (('text_view.js' in result.body) or
                ('text_view.min.js' in result.body))
        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Пример #14
0
    def test_title_description_iframe_shown(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.read',
                            id=self.package.name, resource_id=self.resource_id)
        result = app.get(url)
        assert self.resource_view['title'] in result
        assert self.resource_view['description'] in result
        assert 'data-module="data-viewer"' in result.body

        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Пример #15
0
    def test_title_description_iframe_shown(self):
        # Make a copy of the Pylons config, so we can restore it in teardown.
        original_config = dict(config)
        config['ckan.plugins'] = 'text_view'

        app = helpers._get_test_app()
        with app.flask_app.test_request_context():
            url = h.url_for('resource.read',
                            id=self.package.name, resource_id=self.resource_id)
        result = app.get(url)
        assert self.resource_view['title'] in result
        assert self.resource_view['description'] in result
        assert 'data-module="data-viewer"' in result.body

        # Restore the config to its original values
        config.clear()
        config.update(original_config)
Пример #16
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)
Пример #17
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)
Пример #18
0
 def teardown(self):
     ckan_config.clear()
     ckan_config.update(self._original_config)
Пример #19
0
 def teardown_class(self):
     config.clear()
     config.update(self._original_config)
     mock_mail_server.SmtpServerHarness.teardown_class()
     pylons_controller.PylonsTestCase.teardown_class()
     model.repo.rebuild_db()
Пример #20
0
 def teardown_class(cls):
     config.clear()
     config.update(cls._original_config)
Пример #21
0
 def teardown_class(cls):
     # Restore the config to its original values
     config.clear()
     config.update(cls._original_config)
Пример #22
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)
        PylonsTestCase.teardown_class()

        model.repo.rebuild_db()
Пример #23
0
 def teardown_class(self):
     config.clear()
     config.update(self._original_config)
     mock_mail_server.SmtpServerHarness.teardown_class()
     pylons_controller.PylonsTestCase.teardown_class()
     model.repo.rebuild_db()
Пример #24
0
 def teardown_class(cls):
     rebuild_all_dbs(cls.Session)
     p.unload('datastore')
     p.unload('datapusher')
     config.clear()
     config.update(cls._original_config)
Пример #25
0
 def teardown_class(cls):
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Пример #26
0
 def teardown_class(cls):
     # Restore the config to its original values
     config.clear()
     config.update(cls._original_config)
Пример #27
0
 def teardown(self):
     ckan_config.clear()
     ckan_config.update(self._original_config)
Пример #28
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)

        model.repo.rebuild_db()
Пример #29
0
 def teardown_class(cls):
     config.clear()
     config.update(cls._original_config)
Пример #30
0
 def teardown_class(cls):
     # Restore the Pylons config to its original values, in case any tests
     # changed any config settings.
     config.clear()
     config.update(cls._original_config)
Пример #31
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)
        PylonsTestCase.teardown_class()

        model.repo.rebuild_db()
Пример #32
0
    def teardown_class(cls):
        config.clear()
        config.update(cls._original_config)

        model.repo.rebuild_db()