Skip to content

Commit

Permalink
[ckan#2349] rename new_tests -> tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Mar 18, 2015
1 parent 527a5bf commit 0e731b4
Show file tree
Hide file tree
Showing 71 changed files with 116 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[run]
omit = */migration/*, /tests/*, */new_tests/*
omit = */migration/*, /tests/*
source = ckan, ckanext
38 changes: 3 additions & 35 deletions ckan/ckan_nose_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,9 @@ def startContext(self, ctx):
# import needs to be here or setup happens too early
import ckan.model as model

if 'new_tests' in repr(ctx):
# We don't want to do the stuff below for new-style tests.
if not CkanNose.settings.reset_database:
model.repo.tables_created_and_initialised = True
return

if isclass(ctx):
if hasattr(ctx, "no_db") and ctx.no_db:
return
if (not CkanNose.settings.reset_database
and not CkanNose.settings.ckan_migration):
model.Session.close_all()
model.repo.tables_created_and_initialised = True
model.repo.rebuild_db()
self.is_first_test = False
elif self.is_first_test or CkanNose.settings.ckan_migration:
model.Session.close_all()
model.repo.clean_db()
self.is_first_test = False
if CkanNose.settings.ckan_migration:
model.Session.close_all()
model.repo.upgrade_db()

## This is to make sure the configuration is run again.
## Plugins use configure to make their own tables and they
## may need to be recreated to make tests work.
from ckan.plugins import PluginImplementations
from ckan.plugins.interfaces import IConfigurable
for plugin in PluginImplementations(IConfigurable):
plugin.configure(config)

# init_db is run at the start of every class because
# when you use an in-memory sqlite db, it appears that
# the db is destroyed after every test when you Session.Remove().
model.repo.init_db()
if not CkanNose.settings.reset_database:
model.repo.tables_created_and_initialised = True
return

def options(self, parser, env):
parser.add_option(
Expand Down
Empty file removed ckan/new_tests/logic/__init__.py
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
has the expected side-effects.
* When asserting side-effects after submitting a form, controller tests
should user the :func:`ckan.new_tests.helpers.call_action` function. For
should user the :func:`ckan.tests.helpers.call_action` function. For
example after creating a new user by submitting the new user form, a
test could call the :func:`~ckan.logic.action.get.user_show` action
function to verify that the user was created with the correct values.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
'''
import json

import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers


class TestApiController(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from routes import url_for

from ckan import model
import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories


class TestFeedNew(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from routes import url_for

import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers
import ckan.model as model
from ckan.new_tests import factories
from ckan.tests import factories


class TestGroupController(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import ckan.model as model
import ckan.plugins as p

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories


webtest_submit = helpers.webtest_submit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from routes import url_for

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories


class TestPackageControllerNew(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from routes import url_for as url_for

import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers


class TestUtil(helpers.FunctionalTestBase):
Expand Down
6 changes: 3 additions & 3 deletions ckan/new_tests/factories.py → ckan/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
These are not meant to be used for the actual testing, e.g. if you're writing
a test for the :py:func:`~ckan.logic.action.create.user_create` function then
call :py:func:`~ckan.new_tests.helpers.call_action`, don't test it via the
:py:class:`~ckan.new_tests.factories.User` factory below.
call :py:func:`~ckan.tests.helpers.call_action`, don't test it via the
:py:class:`~ckan.tests.factories.User` factory below.
Usage::
Expand Down Expand Up @@ -41,7 +41,7 @@

import ckan.model
import ckan.logic
import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers


def _get_action_user_name(kwargs):
Expand Down
7 changes: 3 additions & 4 deletions ckan/new_tests/helpers.py → ckan/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import ckan.config.middleware
import ckan.model as model
import ckan.logic as logic
import ckan.new_authz as new_authz


try:
Expand Down Expand Up @@ -77,9 +76,9 @@ def call_action(action_name, context=None, **kwargs):
Note: this skips authorization! It passes 'ignore_auth': True to action
functions in their ``context`` dicts, so the corresponding authorization
functions will not be run.
This is because ckan.new_tests.logic.action tests only the actions, the
This is because ckan.tests.logic.action tests only the actions, the
authorization functions are tested separately in
ckan.new_tests.logic.auth.
ckan.tests.logic.auth.
See the :doc:`testing guidelines </contributing/testing>` for more info.
This function should eventually be moved to
Expand Down Expand Up @@ -109,7 +108,7 @@ def call_auth(auth_name, context, **kwargs):
'''Call the named ``ckan.logic.auth`` function and return the result.
This is just a convenience function for tests in
:py:mod:`ckan.new_tests.logic.auth` to use.
:py:mod:`ckan.tests.logic.auth` to use.
Usage::
Expand Down
3 changes: 0 additions & 3 deletions ckan/tests/legacy/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,6 @@ class TestImportStar(object):
'ckan/migration/versions/064_add_email_last_sent_column.py',
'ckan/migration/versions/065_add_email_notifications_preference.py',
'ckan/plugins/__init__.py',
'ckan/tests/functional/__init__.py',
'ckan/tests/functional/api/base.py',
'ckan/tests/functional/base.py',
'ckan/tests/legacy/functional/api/base.py',
'ckan/tests/legacy/functional/api/test_api.py',
'ckan/tests/legacy/functional/api/test_misc.py',
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ckan import model
from ckan.lib import search

from ckan.new_tests import helpers, factories
from ckan.tests import helpers, factories


class TestGroupListDictize:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import nose.tools

import ckan.new_tests.factories as factories
import ckan.tests.factories as factories


def returns_None(function):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from pylons import config
import ckan.lib.search as search
import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers

assert_equal = nose.tools.assert_equal
assert_in = helpers.assert_in
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from nose import tools as nose_tools

from ckan.new_tests import helpers
from ckan.tests import helpers
from ckan.lib.auth_tkt import make_plugin


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from nose import tools as nose_tools

import ckan.new_tests.factories as factories
import ckan.new_tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.tests.helpers as helpers


class TestLoginView(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from nose.tools import assert_raises

from ckan.lib.cli import UserCmd
import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers

log = logging.getLogger(__name__)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ckan.plugins as p
import ckan.lib.datapreview as datapreview

from ckan.new_tests import helpers, factories
from ckan.tests import helpers, factories


eq_ = nose.tools.eq_
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use mocking.
Tests for action functions should use the
:func:`ckan.new_tests.helpers.call_action` function to call the action
:func:`ckan.tests.helpers.call_action` function to call the action
functions.
One thing :func:`~ckan.new_tests.helpers.call_action` does is to add
One thing :func:`~ckan.tests.helpers.call_action` does is to add
``ignore_auth: True`` into the ``context`` dict that's passed to the action
function, so that CKAN will not call the action function's authorization
function. The tests for an action function *don't* need to cover
authorization, because the authorization functions have their own tests in
:mod:`ckan.new_tests.logic.auth`. But action function tests *do* need to cover
:mod:`ckan.tests.logic.auth`. But action function tests *do* need to cover
validation, more on that later.
Action function tests *should* test the logic of the actions themselves, and
Expand All @@ -24,7 +24,7 @@
Here's an example of a simple :mod:`ckan.logic.action` test:
.. literalinclude:: ../../ckan/new_tests/logic/action/test_update.py
.. literalinclude:: ../../ckan/tests/logic/action/test_update.py
:start-after: ## START-AFTER
:end-before: ## END-BEFORE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import mock
import nose.tools

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.model as model
import ckan.logic as logic
import ckan.plugins as p
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import nose.tools

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.logic as logic
import ckan.model as model
import ckan.plugins as p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import ckan.logic as logic
import ckan.plugins as p
import ckan.lib.search as search
import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories


eq = nose.tools.eq_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import mock
import pylons.config as config

from ckan.new_tests import helpers, factories
from ckan.tests import helpers, factories


class TestPatch(helpers.FunctionalTestBase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import ckan.logic as logic
import ckan.plugins as p
import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories

assert_equals = nose.tools.assert_equals
assert_raises = nose.tools.assert_raises
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
:ref:`mock`.
Tests for auth functions should use the
:func:`ckan.new_tests.helpers.call_auth` function to call auth functions.
:func:`ckan.tests.helpers.call_auth` function to call auth functions.
Here's an example of a simple :py:mod:`ckan.logic.auth` test:
.. literalinclude:: ../../ckan/new_tests/logic/auth/test_update.py
.. literalinclude:: ../../ckan/tests/logic/auth/test_update.py
:start-after: ## START-AFTER
:end-before: ## END-BEFORE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import ckan.model as core_model
import ckan.plugins as p

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.logic.auth.create as auth_create

logic = helpers.logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import nose

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.logic.auth.delete as auth_delete
from ckan import model
import ckan.plugins as p
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from nose.tools import assert_raises

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories
import ckan.logic as logic
from ckan import model

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ckan.model as core_model
import ckan.logic as logic
import ckan.new_tests.helpers as helpers
import ckan.tests.helpers as helpers
import ckan.logic.auth as logic_auth


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import ckan.model as model
import ckan.plugins as p

import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories
import ckan.tests.helpers as helpers
import ckan.tests.factories as factories


assert_equals = nose.tools.assert_equals
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0e731b4

Please sign in to comment.