From 6342ce4500965e5705951e2a478cd21b851e3e1a Mon Sep 17 00:00:00 2001 From: Christoph Ladurner Date: Thu, 21 Mar 2024 11:46:10 +0100 Subject: [PATCH] fix: tests not working since finalize_app --- tests/conftest.py | 6 +++- tests/mock_module/administration/mock.py | 6 ++-- tests/mock_module/ext.py | 35 ++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 tests/mock_module/ext.py diff --git a/tests/conftest.py b/tests/conftest.py index 91a7ffd..b16563e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2022 CERN. +# Copyright (C) 2024 Graz University of Technology. # # invenio-administration is free software; you can redistribute it and/or # modify it under the terms of the MIT License; see LICENSE file for more @@ -43,7 +44,10 @@ def extra_entry_points(): "invenio_administration.views": [ "mock_module = mock_module.administration.mock:MockView", "mock_module = mock_module.administration.mock:MockViewAlternate", - ] + ], + "invenio_base.apps": [ + "test = mock_module.ext:MockExtension", + ], } diff --git a/tests/mock_module/administration/mock.py b/tests/mock_module/administration/mock.py index 451d396..1ca82b9 100644 --- a/tests/mock_module/administration/mock.py +++ b/tests/mock_module/administration/mock.py @@ -2,15 +2,13 @@ # # This file is part of Invenio. # Copyright (C) 2022 CERN. +# Copyright (C) 2024 Graz University of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Mock view for testing.""" -from invenio_administration.views.base import ( - AdminResourceDetailView, - AdminResourceListView, -) +from invenio_administration.views.base import AdminResourceListView class MockView(AdminResourceListView): diff --git a/tests/mock_module/ext.py b/tests/mock_module/ext.py new file mode 100644 index 0000000..d75b5da --- /dev/null +++ b/tests/mock_module/ext.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# +# This file is part of Invenio. +# Copyright (C) 2022 CERN. +# Copyright (C) 2024 Graz University of Technology. +# +# Invenio is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Mock service ext.""" + +from invenio_records_resources.resources import RecordResource +from invenio_records_resources.services import RecordService + +from .administration.mock import MockView +from .config import ServiceConfig +from .resource import MockResource + + +class MockExtension: + """Mock extension.""" + + def __init__(self, app=None): + """Extension initialization.""" + if app: + self.init_app(app) + + def init_app(self, app): + """Init app.""" + mock_service = RecordService(ServiceConfig) + mock_resource = RecordResource(MockResource, mock_service) + + app.extensions["mock-module"] = self + # Adds resource's config name as a class attribute. + self.__dict__[MockView.resource_config] = mock_resource