diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f232b225b..b1ba735d1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,17 +1,28 @@ CHANGELOG ========= -7.0.1 (unreleased) +7.0.3 (unreleased) ------------------ -- Calling context.register() and notify ObjectModifiedEvent after - calling @sort/{field}, @delete/{field} and - @delete/{field}/{file_key} to index changes - [nilbacardit26] + +- Nothing changed yet. + + +7.0.2 (2024-01-23) +------------------ + +- Dummy Release [bloodbare] + + +7.0.1 (2024-01-23) +------------------ + +- Being able to use schema.Time [nilbacardit26] - Feat: Add metadata info to workflows - Fix: Update workflow vocabulary name - Feat: Update workflow vocabulary title attribute to use metadata [rboixaderg] + 7.0.0 (2023-12-06) ------------------ diff --git a/VERSION b/VERSION index e1312611c..6ba11f865 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -7.0.1.dev0 +7.0.3.dev0 diff --git a/guillotina/schema/_field.py b/guillotina/schema/_field.py index 20078c6df..b337f1ee6 100644 --- a/guillotina/schema/_field.py +++ b/guillotina/schema/_field.py @@ -243,8 +243,9 @@ class Time(Orderable, Field): def _validate(self, value): try: - args = [int(unit_time) for unit_time in value.split(":")] - value = time(*args) + if isinstance(value, str): + args = [int(unit_time) for unit_time in value.split(":")] + value = time(*args) except Exception: raise WrongType(value, self._type, self.__name__) super(Time, self)._validate(value) diff --git a/guillotina/tests/test_api.py b/guillotina/tests/test_api.py index 3bf67b6f3..2eb86d8b5 100644 --- a/guillotina/tests/test_api.py +++ b/guillotina/tests/test_api.py @@ -1245,7 +1245,7 @@ class ITestSchema(Interface): object_a = schema.Object(IObjectA, required=False) list_object_a = PatchField(schema.List(value_type=schema.Object(IObjectA), required=False)) - time_ = schema.Time(min="9:00:00", max="11:00:00", required=False) + time_ = schema.Time(min=time(9, 0, 0), max=time(12, 0, 0), required=False) @contenttype(type_name="TestSchema", schema=ITestSchema) @@ -1320,29 +1320,49 @@ async def test_field_values_list_bucket(container_requester): ) assert status == 410 + async def test_time_field_validation(container_requester): async with container_requester as requester: - __import__("pdb").set_trace() resp, status = await requester( - "POST", "/db/guillotina/", data=json.dumps({"@type": "TestSchema", "time_": "16:40:09", "id": "foo_item"}) + "POST", + "/db/guillotina/", + data=json.dumps({"@type": "TestSchema", "time_": "9:00:00", "id": "foo_item"}), ) assert status == 201 + resp, status = await requester("GET", "/db/guillotina/foo_item") + assert status == 200 + assert resp["time_"] == "9:00:00" + resp, status = await requester( - "GET", "/db/guillotina/foo_item", data=json.dumps({"@type": "TestSchema", "time_": "16:40:09"}) + "POST", + "/db/guillotina/", + data=json.dumps({"@type": "TestSchema", "time_": "9:70:00"}), ) - assert status == 200 - assert resp["time"] == "16:40:09" + assert status == 412 resp, status = await requester( - "POST", "/db/guillotina/", data=json.dumps({"@type": "TestSchema", "time_": "16:40:099", "id": "foo_item"}) + "POST", + "/db/guillotina/", + data=json.dumps({"@type": "TestSchema", "time_": "12:00:01"}), ) assert status == 412 + assert resp["deserialization_errors"][0]["message"] == "Value is too big" resp, status = await requester( - "POST", "/db/guillotina/", data=json.dumps({"@type": "TestSchema", "time_": 3600, "id": "foo_item"}) + "POST", + "/db/guillotina/", + data=json.dumps({"@type": "TestSchema", "time_": "8:59:59"}), ) assert status == 412 + assert resp["deserialization_errors"][0]["message"] == "Value is too small" + resp, status = await requester( + "POST", + "/db/guillotina/", + data=json.dumps({"@type": "TestSchema", "time_": 3600}), + ) + assert status == 412 + async def test_patch_field_validation(container_requester): async with container_requester as requester: diff --git a/guillotina/tests/test_serialize.py b/guillotina/tests/test_serialize.py index 0617b0af7..d45266810 100644 --- a/guillotina/tests/test_serialize.py +++ b/guillotina/tests/test_serialize.py @@ -270,6 +270,12 @@ async def test_deserialize_time(dummy_guillotina): assert converted.minute == now.minute +async def test_deserialize_time(dummy_guillotina): + now = time.fromisoformat("10:00:00") + converted = schema_compatible(now, ITestSchema["time"]) + assert converted.minute == now.minute + + async def test_check_permission_deserialize_content(dummy_request): login() content = create_content()