diff --git a/.circleci/config.yml b/.circleci/config.yml index 36c1d2af5be..713dc46d8b3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -77,6 +77,14 @@ jobs: - store_test_results: path: ~/junit + # test_revision_legacy_code is run separately because it mucks up the model for some other tests when nose starts up + - run: + command: | + case $CIRCLE_NODE_INDEX in + 3) nosetests -v --ckan --with-pylons=test-core-circle-ci.ini --nologcapture test_revision_legacy_code.py + ;; + esac + # Tests Frontend, only in one container - run: command: | diff --git a/ckan/lib/activity_streams_session_extension.py b/ckan/lib/activity_streams_session_extension.py deleted file mode 100644 index d623038fbdd..00000000000 --- a/ckan/lib/activity_streams_session_extension.py +++ /dev/null @@ -1,125 +0,0 @@ -# encoding: utf-8 - -from ckan.common import config -from sqlalchemy.orm.session import SessionExtension -from ckan.common import asbool -import logging - -log = logging.getLogger(__name__) - - -def activity_stream_item(obj, activity_type, user_id): - method = getattr(obj, "activity_stream_item", None) - if callable(method): - return method(activity_type, user_id) - else: - # Object did not have a suitable activity_stream_item() method; it must - # not be a package - return None - - -class DatasetActivitySessionExtension(SessionExtension): - """Session extension that emits activity stream activities for packages - and related objects. - - An SQLAlchemy SessionExtension that watches for new, changed or deleted - Packages or objects with related packages (Resources, PackageExtras..) - being committed to the SQLAlchemy session and creates Activity objects for - these activities. - - For most types of activity the Activity objects are created in the relevant - ckan/logic/action/ functions, but for Packages and objects with related - packages they are created by this class instead. - - """ - def before_commit(self, session): - from ckan.model import Member # imported here to avoid dependency hell - if not asbool(config.get('ckan.activity_streams_enabled', 'true')): - return - - session.flush() - - try: - object_cache = session._object_cache - except AttributeError: - # session had no _object_cache; skipping this commit - return - - user = 'DUNNO' # TODO!! - if user: - user_id = user - else: - # If the user is not logged in then revision.user is None and - # revision.author is their IP address. Just log them as 'not logged - # in' rather than logging their IP address. - user_id = 'not logged in' - - # The top-level objects that we will append to the activity table. The - # keys here are package IDs, and the values are model.activity:Activity - # objects. - activities = {} - - # Log new packages first to prevent them from getting incorrectly - # logged as changed packages. - # Looking for new packages... - for obj in object_cache['new']: - activity = activity_stream_item(obj, 'new', user_id) - if activity is None: - continue - # The object returns an activity stream item, so we know that the - # object is a package. - - # Don't create activities for private datasets. - if obj.private: - continue - - activities[obj.id] = activity - - # Now process other objects. - for activity_type in ('new', 'changed', 'deleted'): - objects = object_cache[activity_type] - for obj in objects: - - if not hasattr(obj, "id"): - # Object has no id; skipping - continue - - if (activity_type in ('new', 'changed') and - obj.id in activities): - # This object was already logged as a new package - continue - - try: - related_packages = obj.related_packages() - except (AttributeError, TypeError): - # Object did not have a suitable related_packages() method; - # skipping it - continue - - if isinstance(obj, Member): - # When you add a package to a group/org, it should only be - # in the group's activity stream, not the related packages - continue - - for package in related_packages: - if package is None: - continue - - # Don't create activities for private datasets. - if package.private: - continue - - if package.id in activities: - continue - - activity = activity_stream_item( - package, "changed", user_id) - if activity is None: - continue - activities[package.id] = activity - - for key, activity in activities.items(): - # Emitting activity - session.add(activity) - - session.flush() diff --git a/ckan/model/meta.py b/ckan/model/meta.py index 7c65499d7ca..95f0908a7bc 100644 --- a/ckan/model/meta.py +++ b/ckan/model/meta.py @@ -10,7 +10,6 @@ from sqlalchemy.orm.session import SessionExtension import extension -import ckan.lib.activity_streams_session_extension as activity __all__ = ['Session', 'engine_is_sqlite', 'engine_is_pg'] diff --git a/ckan/tests/legacy/functional/api/test_follow.py b/ckan/tests/legacy/functional/api/test_follow.py index 3db56545773..c8d1641b53f 100644 --- a/ckan/tests/legacy/functional/api/test_follow.py +++ b/ckan/tests/legacy/functional/api/test_follow.py @@ -17,6 +17,10 @@ from ckan.tests.legacy import are_foreign_keys_supported, SkipTest, CreateTestData, call_action_api import ckan.tests.helpers as helpers +# TEMPORARY +# import ckan.migration.revision_legacy_code + + def datetime_from_string(s): '''Return a standard datetime.datetime object initialised from a string in the same format used for timestamps in dictized activities (the format diff --git a/ckan/tests/test_coding_standards.py b/ckan/tests/test_coding_standards.py index 648f9afbfd6..35766aa550e 100644 --- a/ckan/tests/test_coding_standards.py +++ b/ckan/tests/test_coding_standards.py @@ -562,7 +562,7 @@ def find_unprefixed_string_literals(filename): u'ckan/tests/logic/test_schema.py', u'ckan/tests/logic/test_validators.py', u'ckan/tests/migration/__init__.py', - u'ckan/tests/migration/test_revision_legacy_code.py', + u'test_revision_legacy_code.py', u'ckan/tests/model/__init__.py', u'ckan/tests/model/test_license.py', u'ckan/tests/model/test_resource.py', diff --git a/doc/contributing/test.rst b/doc/contributing/test.rst index b0b12e32978..da403334b4e 100644 --- a/doc/contributing/test.rst +++ b/doc/contributing/test.rst @@ -122,7 +122,7 @@ To run CKAN's tests using PostgreSQL as the database, you have to give the ``--with-pylons=test-core.ini`` option on the command line. This command will run the tests for CKAN core and for the core extensions:: - nosetests --ckan --with-pylons=test-core.ini ckan ckanext + nosetests --ckan --with-pylons=test-core.ini ckan ckanext test_revision_legacy_code The speed of the PostgreSQL tests can be improved by running PostgreSQL in memory and turning off durability, as described diff --git a/ckan/tests/migration/test_revision_legacy_code.py b/test_revision_legacy_code.py similarity index 98% rename from ckan/tests/migration/test_revision_legacy_code.py rename to test_revision_legacy_code.py index 3d2da99dce7..2097be3bc0e 100644 --- a/ckan/tests/migration/test_revision_legacy_code.py +++ b/test_revision_legacy_code.py @@ -1,5 +1,9 @@ # encoding: utf-8 +# This file is at the top of the ckan repository, because it needs to be run +# after all the other tests, because it mucks about with the model. + + from difflib import unified_diff from pprint import pprint, pformat