user2913694
user2913694

Reputation:

Running CKAN core tests

I'm trying to run the CKAN tests and it ain't working.

My config (local docker setup, so credentials showing is fine) is at https://gist.github.com/lwm/cd33556fb18d9b8395209cb6233d75af.

I'm quite sure that my postgreSQL, Redis and Solr are set up correctly.

I can see these tests are passing on CKAN HEAD, so I'm pretty stumped.

Here's my test logs:

(default)root@b13dc1f03f32:/usr/lib/ckan/default/src/ckan# nosetests --with-pylons=$CKAN_INI -x
2017-09-12 08:38:39,831 INFO  [ckan.config.environment] Loading static files from public
2017-09-12 08:38:39,860 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2017-09-12 08:38:40,044 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
2017-09-12 08:38:40,158 INFO  [ckan.model] Database tables created
2017-09-12 08:38:40,158 INFO  [ckan.websetup] Creating tables: SUCCESS
.2017-09-12 08:38:40,958 INFO  [ckan.config.environment] Loading templates from /usr/lib/ckan/default/src/ckan/ckan/templates
F
======================================================================
FAIL: ckan.tests.config.test_environment.TestSiteUrlMandatory.test_missing_siteurl
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/ckan/default/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
    self.test(*self.arg)
  File "/usr/lib/ckan/default/src/ckan/ckan/tests/helpers.py", line 389, in wrapper
    return func(*args, **kwargs)
  File "/usr/lib/ckan/default/src/ckan/ckan/tests/config/test_environment.py", line 90, in test_missing_siteurl
    nosetools.assert_raises(RuntimeError, environment.update_config)
AssertionError: RuntimeError not raised

----------------------------------------------------------------------
Ran 2 tests in 1.564s

FAILED (failures=1)

Any pointers are much appreciated!

Upvotes: 1

Views: 126

Answers (1)

amercader
amercader

Reputation: 4540

Some CKAN configuration options can be set via environment variables, like for instance when running it as a Docker container.

These particular tests don't take into account this and will only check if the site url was set directly in the config object, so that's why they pass in a local install and fail inside the container.

To make them more robust you need to make them ignore the setting from the environment variable:

diff --git a/ckan/tests/config/test_environment.py b/ckan/tests/config/test_environment.py
index fafe701..16f1895 100644
--- a/ckan/tests/config/test_environment.py
+++ b/ckan/tests/config/test_environment.py
@@ -85,6 +85,15 @@ class TestUpdateConfig(h.FunctionalTestBase):

 class TestSiteUrlMandatory(object):

+    @classmethod
+    def setup_class(cls):
+        cls._site_url_from_env_var = os.environ.pop('CKAN_SITE_URL', None)
+
+    @classmethod
+    def teardown_class(cls):
+        if cls._site_url_from_env_var:
+            os.environ['CKAN_SITE_URL'] = cls._site_url_from_env_var
+
     @helpers.change_config('ckan.site_url', '')
     def test_missing_siteurl(self):
         nosetools.assert_raises(RuntimeError, environment.update_config)

Feel free to submit a pull request to help improve the tests upstream.

Upvotes: 1

Related Questions