diff --git a/churchtools_api/resources.py b/churchtools_api/resources.py index 5c859ca..c3d0494 100644 --- a/churchtools_api/resources.py +++ b/churchtools_api/resources.py @@ -58,9 +58,9 @@ def get_bookings(self, **kwargs) -> list[dict]: booking_id: int: only one booking by id (use standalone only) resources_ids:list[int]: required if not booking_id status_ids: list[int]: filter by list of stats ids to consider (requires resource_ids) - _from: datetime: date range to consider (use only with _to! - might have a bug in API - Support Ticket 130123) - _to: datetime: date range to consider (use only with _from! - might have a bug in API - Support Ticket 130123) - appointment_id: int: get resources for one specific calendar_appointment only (use together with _to and _from for performance reasons) + from_: datetime: date range to consider (use only with to_! - might have a bug in API - Support Ticket 130123) + to_: datetime: date range to consider (use only with from_! - might have a bug in API - Support Ticket 130123) + appointment_id: int: get resources for one specific calendar_appointment only (use together with to_ and from_ for performance reasons) """ url = self.domain + "/api/bookings" headers = {"accept": "application/json"} @@ -81,15 +81,15 @@ def get_bookings(self, **kwargs) -> list[dict]: if status_ids := kwargs.get("status_ids"): params["status_ids[]"] = status_ids - if "_from" in kwargs or "_to" in kwargs: - if "_from" not in kwargs or "_to" not in kwargs: + if "from_" in kwargs or "to_" in kwargs: + if "from_" not in kwargs or "to_" not in kwargs: logger.info( - "missing _from or _to defaults to first or last day of current month" + "missing from_ or to_ defaults to first or last day of current month" ) - if _from := kwargs.get("_from"): - params["from"] = _from.strftime("%Y-%m-%d") - if _to := kwargs.get("_to"): - params["to"] = _to.strftime("%Y-%m-%d") + if from_ := kwargs.get("from_"): + params["from"] = from_.strftime("%Y-%m-%d") + if to_ := kwargs.get("to_"): + params["to"] = to_.strftime("%Y-%m-%d") if appointment_id := kwargs.get("appointment_id"): if "from" not in params: logger.warning( diff --git a/tests/test_churchtools_api_resources.py b/tests/test_churchtools_api_resources.py index 411ceb5..83e9d50 100644 --- a/tests/test_churchtools_api_resources.py +++ b/tests/test_churchtools_api_resources.py @@ -103,10 +103,10 @@ def test_get_booking_from_to_date_without_resource_id(self, caplog): the hard coded sample exists on ELKW1610.KRZ.TOOLS""" caplog.set_level(logging.WARNING) SAMPLE_DATES = { - "_from": datetime(year=2024, month=12, day=24), - "_to": datetime(year=2024, month=12, day=24), + "from_": datetime(year=2024, month=12, day=24), + "to_": datetime(year=2024, month=12, day=24), } - self.api.get_bookings(_from=SAMPLE_DATES["_from"]) + self.api.get_bookings(from_=SAMPLE_DATES["from_"]) expected_response = "invalid argument combination in get_bookings - please check docstring for requirements" assert expected_response in caplog.messages @@ -117,12 +117,12 @@ def test_get_booking_from_date(self, caplog): caplog.set_level(logging.INFO) RESOURCE_ID_SAMPLES = [8, 20] SAMPLE_DATES = { - "_from": datetime(year=2024, month=9, day=21), - "_to": datetime(year=2024, month=9, day=30), + "from_": datetime(year=2024, month=9, day=21), + "to_": datetime(year=2024, month=9, day=30), } result = self.api.get_bookings( - _from=SAMPLE_DATES["_from"], resource_ids=RESOURCE_ID_SAMPLES + from_=SAMPLE_DATES["from_"], resource_ids=RESOURCE_ID_SAMPLES ) assert set(RESOURCE_ID_SAMPLES) == {i["base"]["resource"]["id"] for i in result} @@ -131,11 +131,11 @@ def test_get_booking_from_date(self, caplog): for i in result } assert all( - [SAMPLE_DATES["_from"] <= compare_date for compare_date in result_dates] + [SAMPLE_DATES["from_"] <= compare_date for compare_date in result_dates] ) expected_response = ( - "missing _from or _to defaults to first or last day of current month" + "missing from_ or to_ defaults to first or last day of current month" ) assert expected_response in caplog.messages @@ -145,11 +145,11 @@ def test_get_booking_to_date(self, caplog): caplog.set_level(logging.INFO) RESOURCE_ID_SAMPLES = [8, 20] SAMPLE_DATES = { - "_to": datetime.now() + timedelta(days=30), + "to_": datetime.now() + timedelta(days=30), } result = self.api.get_bookings( - _to=SAMPLE_DATES["_to"], resource_ids=RESOURCE_ID_SAMPLES + to_=SAMPLE_DATES["to_"], resource_ids=RESOURCE_ID_SAMPLES ) assert set(RESOURCE_ID_SAMPLES) == {i["base"]["resource"]["id"] for i in result} @@ -158,11 +158,11 @@ def test_get_booking_to_date(self, caplog): for i in result } assert all( - [SAMPLE_DATES["_to"] >= compare_date for compare_date in result_dates] + [SAMPLE_DATES["to_"] >= compare_date for compare_date in result_dates] ) expected_response = ( - "missing _from or _to defaults to first or last day of current month" + "missing from_ or to_ defaults to first or last day of current month" ) assert expected_response in caplog.messages @@ -171,15 +171,15 @@ def test_get_booking_from_to_date(self, caplog): the hard coded sample exists on ELKW1610.KRZ.TOOLS""" RESOURCE_ID_SAMPLES = [8, 20] SAMPLE_DATES = { - "_from": datetime(year=2024, month=9, day=21), - "_to": datetime(year=2024, month=9, day=30), + "from_": datetime(year=2024, month=9, day=21), + "to_": datetime(year=2024, month=9, day=30), } caplog.set_level(logging.WARNING) result = self.api.get_bookings( - _from=SAMPLE_DATES["_from"], - _to=SAMPLE_DATES["_to"], + from_=SAMPLE_DATES["from_"], + to_=SAMPLE_DATES["to_"], resource_ids=RESOURCE_ID_SAMPLES, ) assert set(RESOURCE_ID_SAMPLES) == {i["base"]["resource"]["id"] for i in result} @@ -189,10 +189,10 @@ def test_get_booking_from_to_date(self, caplog): for i in result } assert all( - [SAMPLE_DATES["_from"] <= compare_date for compare_date in result_dates] + [SAMPLE_DATES["from_"] <= compare_date for compare_date in result_dates] ) assert all( - [SAMPLE_DATES["_to"] >= compare_date for compare_date in result_dates] + [SAMPLE_DATES["to_"] >= compare_date for compare_date in result_dates] ) assert [] == caplog.messages @@ -204,15 +204,15 @@ def test_get_booking_appointment_id(self, caplog): RESOURCE_ID_SAMPLES = [16] SAMPLE_DATES = { - "_from": datetime(year=2024, month=9, day=21), - "_to": datetime(year=2024, month=9, day=30), + "from_": datetime(year=2024, month=9, day=21), + "to_": datetime(year=2024, month=9, day=30), } SAMPLE_APPOINTMENT_ID = 327883 # 22.9.2024 GH result = self.api.get_bookings( appointment_id=SAMPLE_APPOINTMENT_ID, resource_ids=RESOURCE_ID_SAMPLES, - _from=SAMPLE_DATES["_from"], - _to=SAMPLE_DATES["_to"], + from_=SAMPLE_DATES["from_"], + to_=SAMPLE_DATES["to_"], ) assert result[0]["base"]["caption"] == "Zentral-Gottesdienst im Gemeindehaus" @@ -232,13 +232,13 @@ def test_get_booking_appointment_id_daterange(self): SAMPLE_APPOINTMENT_ID = 327883 SAMPLE_DATES = { - "_from": datetime(year=2024, month=9, day=22), - "_to": datetime(year=2024, month=9, day=22), + "from_": datetime(year=2024, month=9, day=22), + "to_": datetime(year=2024, month=9, day=22), } result = self.api.get_bookings( - _from=SAMPLE_DATES["_from"], - _to=SAMPLE_DATES["_to"], + from_=SAMPLE_DATES["from_"], + to_=SAMPLE_DATES["to_"], appointment_id=SAMPLE_APPOINTMENT_ID, resource_ids=RESOURCE_ID_SAMPLES, ) @@ -249,7 +249,7 @@ def test_get_booking_appointment_id_daterange(self): assert len(result) == 1 # check dates incl. max 1 day diff because of reservations before event start - assert SAMPLE_DATES["_from"] - timedelta(days=1) <= result_date - assert SAMPLE_DATES["_to"] + timedelta(days=1) >= result_date + assert SAMPLE_DATES["from_"] - timedelta(days=1) <= result_date + assert SAMPLE_DATES["to_"] + timedelta(days=1) >= result_date assert result[0]["base"]["caption"] == "Zentral-Gottesdienst im Gemeindehaus" assert result[0]["base"]["resource"]["id"] in set(RESOURCE_ID_SAMPLES)