Skip to content

Commit

Permalink
Merge branch 'master' into index-sort-field
Browse files Browse the repository at this point in the history
  • Loading branch information
nilbacardit26 committed Jan 29, 2024
2 parents 38d40d8 + 05af359 commit 8af91ff
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 16 deletions.
21 changes: 16 additions & 5 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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)
------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.1.dev0
7.0.3.dev0
5 changes: 3 additions & 2 deletions guillotina/schema/_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
36 changes: 28 additions & 8 deletions guillotina/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions guillotina/tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8af91ff

Please sign in to comment.