Skip to content

Commit

Permalink
[#1117] Remove setup db stuff from some new test classes
Browse files Browse the repository at this point in the history
Only test classes that use the db (which should be few of them) need to
do things like cleaning and initing the db. This makes the tests much
faster.
  • Loading branch information
Sean Hammond committed Aug 1, 2013
1 parent 135c59b commit b705361
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
7 changes: 6 additions & 1 deletion ckan/new_tests/helpers.py
Expand Up @@ -8,7 +8,12 @@
def reset_db():
'''Reset CKAN's database.
Each test module or class should call this function in its setup method.
If a test class uses the database, then it should call this function in
its setup() method to make sure that it has a clean database to start with
(nothing left over from other test classes or from previous test runs).
If a test class doesn't use the database (and most test classes shouldn't
need to) then it doesn't need to call this function.
'''
# Close any database connections that have been left open.
Expand Down
6 changes: 6 additions & 0 deletions ckan/new_tests/logic/action/test_update.py
Expand Up @@ -22,13 +22,19 @@ class TestClass(object):

@classmethod
def setup_class(cls):

# Initialize the test db (if it isn't already) and clean out any data
# left in it.
# You should only do this in your setup_class() method if your test
# class uses the db, most test classes shouldn't need to.
helpers.reset_db()

def setup(self):
import ckan.model as model

# Reset the db before each test method.
# You should only do this in your setup() method if your test class
# uses the db, most test classes shouldn't need to.
model.repo.rebuild_db()

def teardown(self):
Expand Down
8 changes: 0 additions & 8 deletions ckan/new_tests/logic/auth/test_update.py
Expand Up @@ -7,14 +7,6 @@

class TestUpdate(object):

@classmethod
def setup_class(cls):
helpers.reset_db()

def setup(self):
import ckan.model as model
model.repo.rebuild_db()

# TODO: Probably all auth function tests want this? Move to helpers.py?
def _call_auth(self, auth_name, context=None, **kwargs):
'''Call a ckan.logic.auth function more conveniently for testing.
Expand Down
11 changes: 0 additions & 11 deletions ckan/new_tests/logic/test_validators.py
Expand Up @@ -211,17 +211,6 @@ def call_and_assert(key, data, errors, context):

class TestValidators(object):

@classmethod
def setup_class(cls):
# Initialize the test db (if it isn't already) and clean out any data
# left in it.
helpers.reset_db()

def setup(self):
import ckan.model as model
# Reset the db before each test method.
model.repo.rebuild_db()

def test_name_validator_with_invalid_value(self):
'''If given an invalid value name_validator() should do raise Invalid.
Expand Down

0 comments on commit b705361

Please sign in to comment.