forked from platformsh/colander-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Colander 2 introduced a extra argument to `colander.Mapping._impl` function (from Pylons/colander#264), which break the `OpenMapping` and `SortedOpenMapping` subclasses from colander-tools. This add the missing argument, as well as a couple of tests to know about it if it ever happen again.
- Loading branch information
Flavien Binet
committed
Aug 4, 2023
1 parent
58e44f1
commit 3dd1762
Showing
3 changed files
with
59 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import colander | ||
from colander_tools import mapping, serializable, strict | ||
from collections import OrderedDict | ||
|
||
def test_open_mapping(): | ||
@serializable.serializable | ||
class Definition(object): | ||
class Schema(colander.MappingSchema): | ||
schema_type = strict.Mapping | ||
|
||
foo = colander.SchemaNode( | ||
mapping.OpenMapping(), | ||
colander.SchemaNode(colander.String(), name="key"), | ||
colander.SchemaNode(strict.Integer(), name="value"), | ||
) | ||
|
||
def __init__(self, foo): | ||
self.foo = foo | ||
|
||
assert Definition.Schema().deserialize({"foo": {"a": 42}}).foo == {"a": 42} | ||
assert Definition.Schema().serialize(Definition(foo={"mykey": 1234})) == {"foo": {"mykey": 1234}} | ||
|
||
|
||
|
||
def test_sorted_open_mapping(): | ||
@serializable.serializable | ||
class Definition(object): | ||
class Schema(colander.MappingSchema): | ||
schema_type = strict.Mapping | ||
|
||
foo = colander.SchemaNode( | ||
mapping.SortedOpenMapping(), | ||
colander.SchemaNode(colander.String(), name="key"), | ||
colander.SchemaNode(strict.Integer(), name="value"), | ||
) | ||
|
||
def __init__(self, foo): | ||
self.foo = foo | ||
|
||
deserialized = Definition.Schema().deserialize({"foo": {"a": 42}}).foo | ||
assert deserialized == {"a": 42} | ||
assert isinstance(deserialized, OrderedDict) | ||
assert Definition.Schema().serialize(Definition(foo={"mykey": 1234})) == {"foo": {"mykey": 1234}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters