Skip to content

Commit

Permalink
Merge pull request ckan#6469 from ckan/faster-tests
Browse files Browse the repository at this point in the history
Faster tests
  • Loading branch information
amercader authored Feb 11, 2022
2 parents 1b9d5ec + 1d221fd commit e4b94b9
Show file tree
Hide file tree
Showing 82 changed files with 1,524 additions and 1,437 deletions.
11 changes: 1 addition & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ defaults:
# Tests Backend, split across containers by segments
run: |
mkdir -p ~/junit
case $CIRCLE_NODE_INDEX in
0) python -m pytest $PYTEST_COMMON_OPTIONS --test-group 1
;;
1) python -m pytest $PYTEST_COMMON_OPTIONS --test-group 2
;;
2) python -m pytest $PYTEST_COMMON_OPTIONS --test-group 3
;;
3) python -m pytest $PYTEST_COMMON_OPTIONS --test-group 4
;;
esac
python -m pytest -v --ckan-ini=test-core-circle-ci.ini --cov=ckan --cov=ckanext --junitxml=/root/junit/junit.xml --splits 4 --group $((CIRCLE_NODE_INDEX+1)) --splitting-algorithm least_duration
ckan_env: &ckan_env
environment:
Expand Down
1 change: 1 addition & 0 deletions .test_durations

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion ckan/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from __future__ import annotations

import logging
from collections import MutableMapping
from collections.abc import MutableMapping
from typing import Any, Container, Optional, Union

import flask
Expand Down
6 changes: 1 addition & 5 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,11 +1119,7 @@ def send_email_notifications(context, data_dict):
command.
'''
# If paste.command_request is True then this function has been called
# by a `paster post ...` command not a real HTTP request, so skip the
# authorization.
if not request.environ.get('paste.command_request'):
_check_access('send_email_notifications', context, data_dict)
_check_access('send_email_notifications', context, data_dict)

if not config.get_value('ckan.activity_streams_email_notifications'):
raise ValidationError('ckan.activity_streams_email_notifications'
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/cli/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def remove_extra_tables():


@pytest.mark.ckan_config("ckan.plugins", "example_database_migrations")
@pytest.mark.usefixtures("with_plugins", "clean_db", "remove_extra_tables")
@pytest.mark.usefixtures("with_plugins", "non_clean_db", "remove_extra_tables")
class TestMigrations:

def test_path_to_alembic_config(self):
Expand Down
33 changes: 17 additions & 16 deletions ckan/tests/cli/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ckan.tests import factories


@pytest.mark.usefixtures(u"clean_db")
@pytest.mark.usefixtures("non_clean_db")
class TestUserAdd(object):

def test_cli_user_add_valid_args(self, cli):
Expand All @@ -17,10 +17,10 @@ def test_cli_user_add_valid_args(self, cli):
args = [
u"user",
u"add",
u"berty",
factories.User.stub().name,
u"password=password123",
u"fullname=Berty Guffball",
u"email=[email protected]",
u"email=" + factories.User.stub().email,
]
result = cli.invoke(ckan, args)

Expand All @@ -38,9 +38,9 @@ def test_cli_user_add_no_fullname(self, cli):
args = [
u"user",
u"add",
u"berty",
factories.User.stub().name,
u"password=password123",
u"email=[email protected]",
u"email=" + factories.User.stub().email,
]
result = cli.invoke(ckan, args)

Expand All @@ -54,10 +54,10 @@ def test_cli_user_add_unicode_fullname_unicode_decode_error(self, cli):
args = [
u"user",
u"add",
u"berty",
factories.User.stub().name,
u"password=password123",
u"fullname=Harold Müffintøp",
u"email=[email protected]",
u"email=" + factories.User.stub().email,
]
result = cli.invoke(ckan, args)
assert not result.exit_code, result.output
Expand All @@ -70,16 +70,16 @@ def test_cli_user_add_unicode_fullname_system_exit(self, cli):
args = [
u"user",
u"add",
u"berty",
factories.User.stub().name,
u"password=password123",
u"fullname=Harold Müffintøp",
u"email=[email protected]",
u"email=" + factories.User.stub().email,
]
result = cli.invoke(ckan, args)
assert not result.exit_code, result.output


@pytest.mark.usefixtures(u"clean_db")
@pytest.mark.usefixtures(u"non_clean_db")
class TestApiToken(object):

def test_revoke(self, cli):
Expand Down Expand Up @@ -110,8 +110,9 @@ def test_list(self, cli):
]
result = cli.invoke(ckan, args)
assert not result.exit_code, result.output
for (id,) in model.Session.query(model.ApiToken.id):
assert id in result.output
tokens = model.Session.query(model.ApiToken.id).filter_by(
user_id=user["id"])
assert all(token.id in result.output for token in tokens)

def test_add_with_extras(self, cli):
"""Command shouldn't raise SystemExit when valid args are provided.
Expand All @@ -126,10 +127,10 @@ def test_add_with_extras(self, cli):
u"""--json={"x": "y"}""",
]

assert model.Session.query(model.ApiToken).count() == 0
initial = model.Session.query(model.ApiToken).count()
result = cli.invoke(ckan, args)
assert not result.exit_code, result.output
assert model.Session.query(model.ApiToken).count() == 1
assert model.Session.query(model.ApiToken).count() == initial + 1

args = [
u"user",
Expand All @@ -143,7 +144,7 @@ def test_add_with_extras(self, cli):

result = cli.invoke(ckan, args)
assert not result.exit_code, result.output
assert model.Session.query(model.ApiToken).count() == 2
assert model.Session.query(model.ApiToken).count() == initial + 2

args = [
u"user",
Expand All @@ -157,4 +158,4 @@ def test_add_with_extras(self, cli):

result = cli.invoke(ckan, args)
assert result.exit_code == 1
assert model.Session.query(model.ApiToken).count() == 2
assert model.Session.query(model.ApiToken).count() == initial + 2
1 change: 0 additions & 1 deletion ckan/tests/config/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


@pytest.mark.ckan_config("ckan.plugins", "test_flash_plugin")
@pytest.mark.usefixtures("with_request_context")
class TestWithFlashPlugin:
def test_flash_populated_by_flask_redirect_to_flask(self, app):
"""
Expand Down
Loading

0 comments on commit e4b94b9

Please sign in to comment.