Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jul 12, 2024
1 parent 881e928 commit ffe5647
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 43 deletions.
6 changes: 3 additions & 3 deletions ckanext/showcase/tests/action/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ckanext.showcase.model import ShowcasePackageAssociation, ShowcaseAdmin


@pytest.mark.usefixtures("clean_db", "showcase_setup", "clean_session")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_session")
class TestCreateShowcase(object):
def test_showcase_create_no_args(self):
"""
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_showcase_create_with_existing_name(self):
)


@pytest.mark.usefixtures("clean_db", "showcase_setup", "clean_session")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_session")
class TestCreateShowcasePackageAssociation(object):
def test_association_create_no_args(self):
"""
Expand Down Expand Up @@ -204,7 +204,7 @@ def test_association_create_existing(self):
)


@pytest.mark.usefixtures("clean_db", "showcase_setup", "clean_session")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_session")
class TestCreateShowcaseAdmin(object):
def test_showcase_admin_add_creates_showcase_admin_user(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions ckanext/showcase/tests/action/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ckan.model.package import Package


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestDeleteShowcase(object):
def test_showcase_delete_no_args(self):
"""
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_showcase_delete_removes_associations(self):
assert model.Session.query(ShowcasePackageAssociation).count() == 0


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestDeletePackage(object):
def test_package_delete_retains_associations(self):
"""
Expand Down Expand Up @@ -192,7 +192,7 @@ def test_package_purge_deletes_associations(self):
assert model.Session.query(ShowcasePackageAssociation).count() == 1


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestDeleteShowcasePackageAssociation(object):
def test_association_delete_no_args(self):
"""
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_association_delete_retains_packages(self):
)


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestRemoveShowcaseAdmin(object):
def test_showcase_admin_remove_deletes_showcase_admin_user(self):
"""
Expand Down
14 changes: 7 additions & 7 deletions ckanext/showcase/tests/action/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import ckan.plugins.toolkit as toolkit


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseShow(object):
def test_showcase_show_no_args(self):
"""
Expand Down Expand Up @@ -201,7 +201,7 @@ def test_showcase_anon_user_can_see_package_list_when_showcase_association_was_d
app.get("/dataset", status=200)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseList(object):
def test_showcase_list(self):
"""Showcase list action returns names of showcases in site."""
Expand Down Expand Up @@ -254,7 +254,7 @@ def test_showcase_list_no_datasets(self):
) not in showcase_list_name_id


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcasePackageList(object):

"""Tests for ckanext_showcase_package_list"""
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_showcase_package_list_package_isnot_a_showcase(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestPackageShowcaseList(object):

"""Tests for ckanext_package_showcase_list"""
Expand Down Expand Up @@ -567,7 +567,7 @@ def test_package_showcase_list_package_isnot_a_showcase(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAdminList(object):

"""Tests for ckanext_showcase_admin_list"""
Expand Down Expand Up @@ -644,7 +644,7 @@ def test_showcase_admin_only_lists_admin_users(self):
} not in showcase_admin_list


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestPackageSearchBeforeSearch(object):

"""
Expand Down Expand Up @@ -693,7 +693,7 @@ def test_package_search_filter_include_showcase(self):
assert "dataset" not in types


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestUserShowBeforeSearch(object):

"""
Expand Down
2 changes: 0 additions & 2 deletions ckanext/showcase/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import ckan.model as model
from ckan.plugins import toolkit

from ckanext.showcase.model import setup as model_setup


@pytest.fixture
def clean_db(reset_db, migrate_db_for):
Expand Down
22 changes: 11 additions & 11 deletions ckanext/showcase/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _get_request(app, url, status):
app.get(url, status=status)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthIndex(object):
def test_auth_anon_user_can_view_showcase_index(self, app):
"""An anon (not logged in) user can view the Showcases index."""
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_auth_sysadmin_can_see_add_showcase_button(self, app):
assert "/showcase/new" in response.body


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthDetails(object):
def test_auth_anon_user_can_view_showcase_details(self, app):
"""
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_auth_showcase_show_sysadmin_can_access(self, app):
assert json_response["success"]


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthCreate(object):
def test_auth_anon_user_cant_view_create_showcase(self, app):
"""
Expand Down Expand Up @@ -251,7 +251,7 @@ def test_auth_sysadmin_can_view_create_showcase_page(self, app):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthList(object):
def test_auth_showcase_list_anon_can_access(self, app):
"""
Expand Down Expand Up @@ -303,7 +303,7 @@ def test_auth_showcase_list_sysadmin_can_access(self, app):
assert json_response["success"]


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthEdit(object):
def test_auth_anon_user_cant_view_edit_showcase_page(self, app):
"""
Expand Down Expand Up @@ -574,7 +574,7 @@ def test_auth_showcase_admin_can_view_addtoshowcase_dropdown_dataset_showcase_li
assert "showcase-add" in showcase_list_response.body


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcasePackageAssociationCreate(object):
def test_showcase_package_association_create_no_user(self):
"""
Expand Down Expand Up @@ -631,7 +631,7 @@ def test_showcase_package_association_create_unauthorized_creds(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcasePackageAssociationDelete(object):
def test_showcase_package_association_delete_no_user(self):
"""
Expand Down Expand Up @@ -688,7 +688,7 @@ def test_showcase_package_association_delete_unauthorized_creds(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAdminAddAuth(object):
def test_showcase_admin_add_no_user(self):
"""
Expand Down Expand Up @@ -723,7 +723,7 @@ def test_showcase_admin_add_unauthorized_creds(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAdminRemoveAuth(object):
def test_showcase_admin_remove_no_user(self):
"""
Expand Down Expand Up @@ -758,7 +758,7 @@ def test_showcase_admin_remove_unauthorized_creds(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAdminListAuth(object):
def test_showcase_admin_list_no_user(self):
"""
Expand Down Expand Up @@ -793,7 +793,7 @@ def test_showcase_admin_list_unauthorized_creds(self):
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseAuthManageShowcaseAdmins(object):
def test_auth_anon_user_cant_view_showcase_admin_manage_page(self, app):
"""
Expand Down
23 changes: 16 additions & 7 deletions ckanext/showcase/tests/test_converters.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import uuid

import pytest

import ckan.model as model
Expand All @@ -10,14 +12,15 @@
)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestNameOrIdToTitleConverter(object):
def test_name_to_title(self):
"""
Package correctly returns title.
"""
my_id = str(uuid.uuid4())
context = {"session": model.Session}
factories.Dataset(id="my-id", title="My Title", name="my-name")
factories.Dataset(id=my_id, title="My Title", name="my-name")

result = convert_package_name_or_id_to_title_or_name(
"my-name", context
Expand All @@ -28,8 +31,10 @@ def test_name_to_name(self):
"""
Package with no title correctly returns name.
"""

my_id = str(uuid.uuid4())
context = {"session": model.Session}
factories.Dataset(id="my-id", title="", name="my-name")
factories.Dataset(id=my_id, title="", name="my-name")

result = convert_package_name_or_id_to_title_or_name(
"my-name", context
Expand All @@ -40,20 +45,24 @@ def test_id_to_title(self):
"""
Package correctly returns title.
"""

my_id = str(uuid.uuid4())
context = {"session": model.Session}
factories.Dataset(id="my-id", title="My Title", name="my-name")
factories.Dataset(id=my_id, title="My Title", name="my-name")

result = convert_package_name_or_id_to_title_or_name("my-id", context)
result = convert_package_name_or_id_to_title_or_name(my_id, context)
assert "My Title" == result

def test_id_to_name(self):
"""
Package with no title correctly returns name.
"""

my_id = str(uuid.uuid4())
context = {"session": model.Session}
factories.Dataset(id="my-id", title="", name="my-name")
factories.Dataset(id=my_id, title="", name="my-name")

result = convert_package_name_or_id_to_title_or_name("my-id", context)
result = convert_package_name_or_id_to_title_or_name(my_id, context)
assert "my-name" == result

def test_with_no_package_id_exists(self):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/showcase/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import ckanext.showcase.logic.helpers as showcase_helpers


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestGetSiteStatistics(object):
def test_dataset_count_no_datasets(self):
"""
Expand Down
14 changes: 7 additions & 7 deletions ckanext/showcase/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
log = logging.getLogger(__name__)


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseIndex(object):
def test_showcase_listed_on_index(self, app):
"""
Expand All @@ -30,7 +30,7 @@ def test_showcase_listed_on_index(self, app):
assert "my-showcase" in response.body


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseNewView(object):
def test_showcase_create_form_renders(self, app):

Expand Down Expand Up @@ -83,7 +83,7 @@ def test_create_showcase(self, app):



@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestShowcaseEditView(object):
def test_showcase_edit_form_renders(self, app):
"""
Expand Down Expand Up @@ -145,7 +145,7 @@ def test_edit_showcase(self, app):
assert "My new description!" in res.body


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestDatasetView(object):

"""Plugin adds a new showcases view for datasets."""
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_dataset_showcase_page_remove_showcase_button_submit(self, app):
assert model.Session.query(ShowcasePackageAssociation).count() == 0


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestShowcaseAdminManageView(object):

"""Plugin adds a showcase admin management page to ckan-admin section."""
Expand Down Expand Up @@ -392,7 +392,7 @@ def test_showcase_admin_manage_page_no_admins_message(self, app):
assert "There are currently no Showcase Admins" in response


@pytest.mark.usefixtures("clean_db", "clean_index")
@pytest.mark.usefixtures("with_plugins", "clean_db", "clean_index")
class TestSearch(object):
def test_search_with_nonascii_filter_query(self, app):
"""
Expand All @@ -407,7 +407,7 @@ def test_search_with_nonascii_filter_query(self, app):
assert result["count"] == 1


@pytest.mark.usefixtures('clean_db')
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestCKEditor(object):
@pytest.mark.ckan_config("ckanext.showcase.editor", "ckeditor")
def test_rich_text_editor_is_shown_when_configured(self, app):
Expand Down
2 changes: 1 addition & 1 deletion ckanext/showcase/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ckanext.showcase.utils import markdown_to_html


@pytest.mark.usefixtures("clean_db")
@pytest.mark.usefixtures("with_plugins", "clean_db")
class TestUtils(object):

def test_markdown_to_html(self):
Expand Down

0 comments on commit ffe5647

Please sign in to comment.