Skip to content

Commit

Permalink
fix: tests not working since finalize_app
Browse files Browse the repository at this point in the history
* the problem was that the mock fixtures were called after the app creation.
  this does not work because in the finalize_app they have to be ready already.
  therefore they are now called as a entry point before of the finalize_app
  • Loading branch information
utnapischtim authored and kpsherva committed Mar 22, 2024
1 parent b3105dc commit ea1bb5c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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",
],
}


Expand Down
6 changes: 2 additions & 4 deletions tests/mock_module/administration/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
35 changes: 35 additions & 0 deletions tests/mock_module/ext.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ea1bb5c

Please sign in to comment.