Skip to content

Commit

Permalink
Emit activities in create tests data, avoid leaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 18, 2019
1 parent ba015a5 commit 3d9f8ee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 6 additions & 0 deletions ckan/lib/create_test_data.py
Expand Up @@ -466,6 +466,12 @@ def create(cls, auth_profile="", package_type=None):
sysadmin,
])
cls.user_refs.extend([u'tester', u'joeadmin', u'annafan', u'russianfan', u'testsysadmin'])

# Create activities for packages
for item in [pkg1, pkg2]:
activity = item.activity_stream_item('new', 'not logged in')
model.Session.add(activity)

model.repo.commit_and_remove()

# method used in DGU and all good tests elsewhere
Expand Down
25 changes: 12 additions & 13 deletions ckan/tests/migration/test_revision_legacy_code.py
Expand Up @@ -8,6 +8,7 @@
import ckan.lib.search as search
from ckan.lib.dictization.model_save import package_dict_save
from ckan.lib.create_test_data import CreateTestData
from ckan.tests import helpers

from ckan.migration.revision_legacy_code import package_dictize_with_revisions as package_dictize
from ckan.migration.revision_legacy_code import RevisionTableMappings, make_package_revision
Expand All @@ -18,11 +19,6 @@
class TestPackageDictizeWithRevisions(object):
@classmethod
def setup_class(cls):
# clean the db so we can run these tests on their own
model.repo.rebuild_db()
search.clear_all()
CreateTestData.create()
make_package_revision(model.Package.by_name('annakarenina'))

cls.package_expected = {
u'author': None,
Expand Down Expand Up @@ -124,12 +120,17 @@ def setup_class(cls):
u'type': u'dataset',
u'url': u'http://datahub.io',
u'version': u'0.7a',
}
}

@classmethod
def teardown_class(cls):
model.repo.rebuild_db()
model.Session.remove()
def setup(self):
helpers.reset_db()
search.clear_all()
CreateTestData.create()
make_package_revision(model.Package.by_name('annakarenina'))

def teardown(self):
helpers.reset_db()
search.clear_all()

def test_09_package_alter(self):

Expand Down Expand Up @@ -201,12 +202,10 @@ def test_09_package_alter(self):
model.Session.remove()
make_package_revision(model.Package.by_name('annakarenina_changed2'))

def test_13_get_package_in_past(self):

context = {'model': model,
'session': model.Session}

anna1 = model.Session.query(model.Package).filter_by(name='annakarenina_changed2').one() # this depends on the previous test running :(
anna1 = model.Session.query(model.Package).filter_by(name='annakarenina_changed2').one()

pkgrevisions = model.Session.query(RevisionTableMappings.instance().PackageRevision).filter_by(id=anna1.id).all()
sorted_packages = sorted(pkgrevisions, key=lambda x: x.revision_timestamp)
Expand Down

0 comments on commit 3d9f8ee

Please sign in to comment.