Skip to content

Commit

Permalink
CI: add extra db param to installation
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Nov 30, 2023
1 parent 9554a25 commit d56f6e4
Show file tree
Hide file tree
Showing 17 changed files with 176 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
matrix:
python-version: [3.9]
requirements-level: [pypi]
db-service: [postgresql13, postgres14]
db-service: [postgresql13, postgresql14]
search-service: [elasticsearch7, opensearch2]
include:
- search-service: opensearch2
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os

import sphinx.environment

from invenio_circulation import __version__

# -- General configuration ------------------------------------------------
Expand Down
52 changes: 37 additions & 15 deletions invenio_circulation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,44 @@
from .api import Loan
from .links import loan_links_factory
from .permissions import views_permissions_factory
from .pidstore.pids import _LOANID_CONVERTER, CIRCULATION_LOAN_FETCHER, \
CIRCULATION_LOAN_MINTER, CIRCULATION_LOAN_PID_TYPE
from .pidstore.pids import (
_LOANID_CONVERTER,
CIRCULATION_LOAN_FETCHER,
CIRCULATION_LOAN_MINTER,
CIRCULATION_LOAN_PID_TYPE,
)
from .search.api import LoansSearch
from .transitions.transitions import CreatedToPending, \
ItemAtDeskToItemOnLoan, ItemInTransitHouseToItemReturned, \
ItemOnLoanToItemInTransitHouse, ItemOnLoanToItemOnLoan, \
ItemOnLoanToItemReturned, PendingToItemAtDesk, \
PendingToItemInTransitPickup, ToCancelled, ToItemOnLoan
from .utils import can_be_requested, document_exists, document_ref_builder, \
get_default_extension_duration, get_default_extension_max_count, \
get_default_loan_duration, is_loan_duration_valid, item_can_circulate, \
item_exists, item_location_retriever, item_ref_builder, patron_exists, \
patron_ref_builder, same_location_validator, \
transaction_location_validator, transaction_user_validator, \
validate_item_pickup_transaction_locations
from .transitions.transitions import (
CreatedToPending,
ItemAtDeskToItemOnLoan,
ItemInTransitHouseToItemReturned,
ItemOnLoanToItemInTransitHouse,
ItemOnLoanToItemOnLoan,
ItemOnLoanToItemReturned,
PendingToItemAtDesk,
PendingToItemInTransitPickup,
ToCancelled,
ToItemOnLoan,
)
from .utils import (
can_be_requested,
document_exists,
document_ref_builder,
get_default_extension_duration,
get_default_extension_max_count,
get_default_loan_duration,
is_loan_duration_valid,
item_can_circulate,
item_exists,
item_location_retriever,
item_ref_builder,
patron_exists,
patron_ref_builder,
same_location_validator,
transaction_location_validator,
transaction_user_validator,
validate_item_pickup_transaction_locations,
)

CIRCULATION_ITEMS_RETRIEVER_FROM_DOCUMENT = None
"""Function that returns a list of item PIDs given a Document PID."""
Expand Down Expand Up @@ -183,7 +206,6 @@
pid_minter=CIRCULATION_LOAN_MINTER,
pid_fetcher=CIRCULATION_LOAN_FETCHER,
search_class=LoansSearch,
search_type=None,
record_class=Loan,
record_loaders={
"application/json": (
Expand Down
7 changes: 5 additions & 2 deletions invenio_circulation/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

from . import config
from .api import Loan
from .errors import InvalidLoanStateError, NoValidTransitionAvailableError, \
TransitionConditionsFailedError
from .errors import (
InvalidLoanStateError,
NoValidTransitionAvailableError,
TransitionConditionsFailedError,
)
from .pidstore.pids import CIRCULATION_LOAN_PID_TYPE
from .search.api import LoansSearch
from .transitions.base import Transition
Expand Down
4 changes: 2 additions & 2 deletions invenio_circulation/records/loaders/schemas/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def deserialize(self, value, attr=None, data=None, **kwargs):
_value = super().deserialize(value, attr, data, **kwargs)
# return the value as string after marshmallow validation
# because Invenio does not support Python datetime JSON serializer yet
if _value and type(_value) == datetime:
if _value and isinstance(_value, datetime):
return _value.isoformat()
return _value

Expand All @@ -60,7 +60,7 @@ def deserialize(self, value, attr=None, data=None, **kwargs):
_value = super().deserialize(value, attr, data, **kwargs)
# return the value as string after marshmallow validation
# because Invenio does not support Python datetime JSON serializer yet
if _value and type(_value) == date:
if _value and isinstance(_value, date):
return _value.isoformat()
return _value

Expand Down
14 changes: 10 additions & 4 deletions invenio_circulation/transitions/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
from invenio_db import db

from ..api import Loan, is_item_available_for_checkout
from ..errors import DocumentDoNotMatchError, DocumentNotAvailableError, \
InvalidLoanStateError, InvalidPermissionError, ItemNotAvailableError, \
MissingRequiredParameterError, TransitionConditionsFailedError, \
TransitionConstraintsViolationError
from ..errors import (
DocumentDoNotMatchError,
DocumentNotAvailableError,
InvalidLoanStateError,
InvalidPermissionError,
ItemNotAvailableError,
MissingRequiredParameterError,
TransitionConditionsFailedError,
TransitionConstraintsViolationError,
)
from ..proxies import current_circulation
from ..signals import loan_state_changed
from ..utils import str2datetime
Expand Down
21 changes: 15 additions & 6 deletions invenio_circulation/transitions/transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@

from invenio_circulation.proxies import current_circulation

from ..api import can_be_requested, get_available_item_by_doc_pid, \
get_document_pid_by_item_pid, get_pending_loans_by_doc_pid, \
is_item_at_desk_available_for_checkout
from ..errors import ItemDoNotMatchError, ItemNotAvailableError, \
LoanMaxExtensionError, RecordCannotBeRequestedError, \
TransitionConditionsFailedError, TransitionConstraintsViolationError
from ..api import (
can_be_requested,
get_available_item_by_doc_pid,
get_document_pid_by_item_pid,
get_pending_loans_by_doc_pid,
is_item_at_desk_available_for_checkout,
)
from ..errors import (
ItemDoNotMatchError,
ItemNotAvailableError,
LoanMaxExtensionError,
RecordCannotBeRequestedError,
TransitionConditionsFailedError,
TransitionConstraintsViolationError,
)
from ..transitions.base import Transition


Expand Down
7 changes: 5 additions & 2 deletions invenio_circulation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
from invenio_records_rest.views import pass_record
from invenio_rest import ContentNegotiatedMethodView

from .errors import InvalidLoanStateError, ItemNotAvailableError, \
MissingRequiredParameterError
from .errors import (
InvalidLoanStateError,
ItemNotAvailableError,
MissingRequiredParameterError,
)
from .permissions import need_permissions
from .pidstore.pids import _LOANID_CONVERTER, CIRCULATION_LOAN_PID_TYPE
from .proxies import current_circulation
Expand Down
30 changes: 26 additions & 4 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,37 @@ set -o errexit
# Quit on unbound symbols
set -o nounset

# Always bring down docker services
function cleanup() {
# Define function for bringing down services
function cleanup {
eval "$(docker-services-cli down --env)"
}
trap cleanup EXIT

# Check for arguments
# Note: "-k" would clash with "pytest"
keep_services=0
pytest_args=()
for arg in $@; do
# from the CLI args, filter out some known values and forward the rest to "pytest"
# note: we don't use "getopts" here b/c of some limitations (e.g. long options),
# which means that we can't combine short options (e.g. "./run-tests -Kk pattern")
case ${arg} in
-K|--keep-services)
keep_services=1
;;
*)
pytest_args+=( ${arg} )
;;
esac
done

if [[ ${keep_services} -eq 0 ]]; then
trap cleanup EXIT
fi


python -m check_manifest --ignore ".*-requirements.txt"
python -m sphinx.cmd.build -qnNW docs docs/_build/html
eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-elasticsearch} --cache ${CACHE:-redis} --env)"
eval "$(docker-services-cli up --db ${DB:-postgresql} --search ${SEARCH:-opensearch} --cache ${CACHE:-redis} --env)"
python -m pytest
tests_exit_code=$?
python -m sphinx.cmd.build -qnNW -b doctest docs docs/_build/doctest
Expand Down
18 changes: 10 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ all_files = 1
[bdist_wheel]
universal = 1

[pydocstyle]
add_ignore = D401

[pycodestyle]
exclude = docs/conf.py

[compile_catalog]
directory = invenio_circulation/translations/

Expand All @@ -123,10 +117,18 @@ output-dir = invenio_circulation/translations/
[isort]
profile=black

[pydocstyle]
add_ignore = D401

[pycodestyle]
max-line-length = 88
exclude = docs/conf.py

[check-manifest]
ignore =
*-requirements.txt

[tool:pytest]
addopts = --black --isort --pydocstyle --doctest-glob="*.rst" --doctest-modules --cov=invenio_circulation --cov-report=term-missing
testpaths = tests invenio_circulation
addopts = --black --isort --pydocstyle --doctest-glob="*.rst" --doctest-modules --cov=invenio_administration --cov-report=term-missing
filterwarnings = ignore::pytest.PytestDeprecationWarning
testpaths = tests invenio_administration
26 changes: 19 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,25 @@
from invenio_circulation.pidstore.minters import loan_pid_minter

from .helpers import create_loan, test_views_permissions_factory
from .utils import can_be_requested, document_exists, document_ref_builder, \
get_default_extension_duration, get_default_extension_max_count, \
get_default_loan_duration, is_loan_duration_valid, item_can_circulate, \
item_exists, item_location_retriever, item_ref_builder, patron_exists, \
patron_ref_builder, same_location_validator, \
transaction_location_validator, transaction_user_validator, \
validate_item_pickup_transaction_locations
from .utils import (
can_be_requested,
document_exists,
document_ref_builder,
get_default_extension_duration,
get_default_extension_max_count,
get_default_loan_duration,
is_loan_duration_valid,
item_can_circulate,
item_exists,
item_location_retriever,
item_ref_builder,
patron_exists,
patron_ref_builder,
same_location_validator,
transaction_location_validator,
transaction_user_validator,
validate_item_pickup_transaction_locations,
)


@pytest.fixture(scope="module")
Expand Down
19 changes: 13 additions & 6 deletions tests/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@

import pytest

from invenio_circulation.errors import InvalidLoanStateError, \
InvalidPermissionError, ItemNotAvailableError, LoanMaxExtensionError, \
MissingRequiredParameterError, MultipleLoansOnItemError, \
NotImplementedConfigurationError, NoValidTransitionAvailableError, \
RecordCannotBeRequestedError, TransitionConditionsFailedError, \
TransitionConstraintsViolationError
from invenio_circulation.errors import (
InvalidLoanStateError,
InvalidPermissionError,
ItemNotAvailableError,
LoanMaxExtensionError,
MissingRequiredParameterError,
MultipleLoansOnItemError,
NotImplementedConfigurationError,
NoValidTransitionAvailableError,
RecordCannotBeRequestedError,
TransitionConditionsFailedError,
TransitionConstraintsViolationError,
)


def test_not_implemented(app):
Expand Down
9 changes: 6 additions & 3 deletions tests/test_loan_base_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
import arrow
import pytest

from invenio_circulation.errors import ItemDoNotMatchError, \
ItemNotAvailableError, MissingRequiredParameterError, \
TransitionConstraintsViolationError
from invenio_circulation.errors import (
ItemDoNotMatchError,
ItemNotAvailableError,
MissingRequiredParameterError,
TransitionConstraintsViolationError,
)
from invenio_circulation.pidstore.fetchers import loan_pid_fetcher
from invenio_circulation.proxies import current_circulation

Expand Down
7 changes: 5 additions & 2 deletions tests/test_loan_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
"""Tests for loan search class."""

from invenio_circulation.api import Loan
from invenio_circulation.search.api import search_by_patron_item_or_document, \
search_by_patron_pid, search_by_pid
from invenio_circulation.search.api import (
search_by_patron_item_or_document,
search_by_patron_pid,
search_by_pid,
)


def _assert_total(total, expected):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

import pytest

from invenio_circulation.errors import NotImplementedConfigurationError, \
NoValidTransitionAvailableError
from invenio_circulation.errors import (
NotImplementedConfigurationError,
NoValidTransitionAvailableError,
)
from invenio_circulation.proxies import current_circulation
from invenio_circulation.utils import \
validate_item_pickup_transaction_locations
from invenio_circulation.utils import validate_item_pickup_transaction_locations

from .helpers import SwappedConfig

Expand Down
6 changes: 4 additions & 2 deletions tests/test_loan_transition_to_item_on_loan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import arrow
import pytest

from invenio_circulation.errors import ItemNotAvailableError, \
TransitionConstraintsViolationError
from invenio_circulation.errors import (
ItemNotAvailableError,
TransitionConstraintsViolationError,
)
from invenio_circulation.proxies import current_circulation

from .helpers import SwappedConfig
Expand Down
17 changes: 12 additions & 5 deletions tests/test_loan_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@
import pytest
from flask_security import login_user

from invenio_circulation.api import get_loan_for_item, \
is_item_at_desk_available_for_checkout, is_item_available_for_checkout
from invenio_circulation.errors import ItemDoNotMatchError, \
LoanMaxExtensionError, NoValidTransitionAvailableError, \
RecordCannotBeRequestedError, TransitionConstraintsViolationError
from invenio_circulation.api import (
get_loan_for_item,
is_item_at_desk_available_for_checkout,
is_item_available_for_checkout,
)
from invenio_circulation.errors import (
ItemDoNotMatchError,
LoanMaxExtensionError,
NoValidTransitionAvailableError,
RecordCannotBeRequestedError,
TransitionConstraintsViolationError,
)
from invenio_circulation.proxies import current_circulation
from invenio_circulation.utils import str2datetime

Expand Down

0 comments on commit d56f6e4

Please sign in to comment.