diff --git a/MANIFEST.in b/MANIFEST.in index 11a7e4faae..27c46d7733 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -24,6 +24,7 @@ include docker/haproxy/Dockerfile include docker/nginx/Dockerfile include docker/postgres/Dockerfile include Dockerfile +exclude scripts/all_year_days include scripts/bootstrap include scripts/console include scripts/dojson_virtua diff --git a/scripts/all_year_days b/scripts/all_year_days new file mode 100755 index 0000000000..791632dfe2 --- /dev/null +++ b/scripts/all_year_days @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Launch a command every day of current year +# +# Depends on: faketime (`apt install faketime` i.e.) +# +# EXAMPLE: +# ./scripts/all_year_days pipenv run pytest -vvs --no-cov --disable-warnings tests/api/test_loans_rest.py +# + +# variables +launch_command="$@" + +# functions +error+exit() { + echo -e "$1" && exit 1 +} + +# tests +if [[ -z "${launch_command}" ]]; then + echo "No command given." && exit 1 +fi + +if [[ -z $(which faketime) ]]; then + echo "faketime command is missing! Please install libfaketime." && exit 1 +fi + +# initialization +current_year=`date +"%Y"` +# display all days of year (from current year) +for i in {0..366}; do + if [[ "$(uname -s)" == "Darwin" ]]; then + date="$(date -j -v01m -v01d -v${current_year}y -v+${i}d '+%Y-%m-%d') 9:30:42" + else + date="$(date -u +"%Y-%m-%d" -d "${current_year}-01-01 +$i days") 9:30:42" + fi + # display choosen date + echo -e "#### CHOOSEN DATE: ${date} ####" + faketime "${date}" ${launch_command} \ + || error+exit "'${launch_command}' FAILED this day: ${date}." +done + +# end +exit 0 +#vim: ts=2 sw=2 et nu diff --git a/tests/api/test_loans_rest.py b/tests/api/test_loans_rest.py index f425b15f12..df3beba5e4 100644 --- a/tests/api/test_loans_rest.py +++ b/tests/api/test_loans_rest.py @@ -38,6 +38,9 @@ from rero_ils.modules.notifications.api import NotificationsSearch, \ number_of_reminders_sent +# Display current system time +print("\n#### PYTHON KNOWN DATE: %s ####\n" % datetime.now()) + def test_loans_permissions(client, loan_pending_martigny, json_header): """Test record retrieval.""" @@ -177,9 +180,8 @@ def test_due_soon_loans(client, librarian_martigny_no_email, checkout_loan = Loan.get_record_by_pid(loan_pid) loan_date = ciso8601.parse_datetime(checkout_loan.get('end_date')) - # should be 22:59 in UTC+0 - tocheck_date = loan_date - assert tocheck_date.minute == 59 and tocheck_date.hour == 22 + # as instance timezone is Europe/Zurich, it should be either 21 or 22 + check_timezone_date(pytz.utc, loan_date, [21, 22]) # should be 14:59/15:59 in US/Pacific (because of daylight saving time) check_timezone_date(pytz.timezone('US/Pacific'), loan_date, [14, 15]) @@ -511,4 +513,4 @@ def test_timezone_due_date(client, librarian_martigny_no_email, assert loan_datetime.month == lib_datetime.month, fail_msg assert loan_datetime.day == lib_datetime.day, fail_msg # Loan date differs regarding timezone, and day of the year (GMT+1/2). - check_timezone_date(pytz.utc, loan_datetime, [22, 23]) + check_timezone_date(pytz.utc, loan_datetime, [21, 22])