diff --git a/ckan/pastertemplates/template/bin/travis-build.bash_tmpl b/ckan/pastertemplates/template/bin/travis-build.bash_tmpl index 44d0531e4d6..c58598a917f 100755 --- a/ckan/pastertemplates/template/bin/travis-build.bash_tmpl +++ b/ckan/pastertemplates/template/bin/travis-build.bash_tmpl @@ -22,6 +22,11 @@ echo "Creating the PostgreSQL user and database..." sudo -u postgres psql -c "CREATE USER ckan_default WITH PASSWORD 'pass';" sudo -u postgres psql -c 'CREATE DATABASE ckan_test WITH OWNER ckan_default;' +echo "SOLR config..." +# Solr is multicore for tests on ckan master, but it's easier to run tests on +# Travis single-core. See https://github.com/ckan/ckan/issues/2972 +sed -i -e 's/solr_url.*/solr_url = http:\/\/127.0.0.1:8983\/solr/' ckan/test-core.ini + echo "Initialising the database..." cd ckan paster db init -c test-core.ini diff --git a/ckan/tests/helpers.py b/ckan/tests/helpers.py index a1f24928739..f41e850cf78 100644 --- a/ckan/tests/helpers.py +++ b/ckan/tests/helpers.py @@ -414,3 +414,31 @@ def wrapper(*args, **kwargs): return return_value return nose.tools.make_decorator(func)(wrapper) return decorator + + +def find_flask_app(test_app): + ''' + Helper function to recursively search the wsgi stack in `test_app` until + the flask_app is discovered. + + Relies on each layer of the stack having a reference to the app they + wrap in either a .app attribute or .apps list. + ''' + if isinstance(test_app, ckan.config.middleware.CKANFlask): + return test_app + + try: + app = test_app.apps['flask_app'].app + except (AttributeError, KeyError): + pass + else: + return find_flask_app(app) + + try: + app = test_app.app + except AttributeError: + print('No .app attribute. ' + 'Have all layers of the stack got ' + 'a reference to the app they wrap?') + else: + return find_flask_app(app) diff --git a/ckanext/datapusher/logic/action.py b/ckanext/datapusher/logic/action.py index 8ce97c2bc8f..5afb4b0b33a 100644 --- a/ckanext/datapusher/logic/action.py +++ b/ckanext/datapusher/logic/action.py @@ -74,7 +74,7 @@ def datapusher_submit(context, data_dict): 'entity_id': res_id, 'entity_type': 'resource', 'task_type': 'datapusher', - 'last_updated': str(datetime.datetime.now()), + 'last_updated': str(datetime.datetime.utcnow()), 'state': 'submitting', 'key': 'datapusher', 'value': '{}', @@ -119,7 +119,7 @@ def datapusher_submit(context, data_dict): 'details': str(e)} task['error'] = json.dumps(error) task['state'] = 'error' - task['last_updated'] = str(datetime.datetime.now()), + task['last_updated'] = str(datetime.datetime.utcnow()), p.toolkit.get_action('task_status_update')(context, task) raise p.toolkit.ValidationError(error) @@ -134,7 +134,7 @@ def datapusher_submit(context, data_dict): 'status_code': r.status_code} task['error'] = json.dumps(error) task['state'] = 'error' - task['last_updated'] = str(datetime.datetime.now()), + task['last_updated'] = str(datetime.datetime.utcnow()), p.toolkit.get_action('task_status_update')(context, task) raise p.toolkit.ValidationError(error) @@ -143,7 +143,7 @@ def datapusher_submit(context, data_dict): task['value'] = value task['state'] = 'pending' - task['last_updated'] = str(datetime.datetime.now()), + task['last_updated'] = str(datetime.datetime.utcnow()), p.toolkit.get_action('task_status_update')(context, task) return True @@ -175,7 +175,7 @@ def datapusher_hook(context, data_dict): }) task['state'] = status - task['last_updated'] = str(datetime.datetime.now()) + task['last_updated'] = str(datetime.datetime.utcnow()) resubmit = False diff --git a/ckanext/datapusher/tests/test_action.py b/ckanext/datapusher/tests/test_action.py index 218406ccbaf..7c24612d9e6 100644 --- a/ckanext/datapusher/tests/test_action.py +++ b/ckanext/datapusher/tests/test_action.py @@ -30,7 +30,7 @@ def _pending_task(self, resource_id): 'entity_id': resource_id, 'entity_type': 'resource', 'task_type': 'datapusher', - 'last_updated': str(datetime.datetime.now()), + 'last_updated': str(datetime.datetime.utcnow()), 'state': 'pending', 'key': 'datapusher', 'value': '{}', @@ -163,13 +163,14 @@ def test_resubmits_if_upload_changes_in_the_meantime( **self._pending_task(resource['id'])) # Update the resource, set a new last_modified (changes on file upload) - helpers.call_action('resource_update', {}, - id=resource['id'], - package_id=dataset['id'], - url='http://example.com/file.csv', - format='CSV', - last_modified=datetime.datetime.now().isoformat() - ) + helpers.call_action( + 'resource_update', {}, + id=resource['id'], + package_id=dataset['id'], + url='http://example.com/file.csv', + format='CSV', + last_modified=datetime.datetime.utcnow().isoformat() + ) # Not called eq_(len(mock_datapusher_submit.mock_calls), 1) diff --git a/ckanext/example_flask_iroutes/tests/test_routes.py b/ckanext/example_flask_iroutes/tests/test_routes.py index fa8110c76c8..8e4dcc1799f 100644 --- a/ckanext/example_flask_iroutes/tests/test_routes.py +++ b/ckanext/example_flask_iroutes/tests/test_routes.py @@ -1,41 +1,14 @@ from nose.tools import eq_, ok_ -from ckan.config.middleware import CKANFlask import ckan.plugins as plugins import ckan.tests.helpers as helpers class TestFlaskIRoutes(helpers.FunctionalTestBase): - @classmethod - def _find_flask_app(cls, test_app): - '''Recursively search the wsgi stack until the flask_app is - discovered. - - Relies on each layer of the stack having a reference to the app they - wrap in either a .app attribute or .apps list. - ''' - if isinstance(test_app, CKANFlask): - return test_app - - try: - app = test_app.apps['flask_app'].app - except (AttributeError, KeyError): - pass - else: - return cls._find_flask_app(app) - - try: - app = test_app.app - except AttributeError: - print('No .app attribute. ' - 'Have all layers of the stack got ' - 'a reference to the app they wrap?') - else: - return cls._find_flask_app(app) def setup(self): self.app = helpers._get_test_app() - flask_app = self._find_flask_app(self.app) + flask_app = helpers.find_flask_app(self.app) # Blueprints can't be registered after the app has been setup. For # some reason, if debug is True, the app will have exited its initial