コード例 #1
0
def test_list(engine):
    typedef = List(UUID)
    loaded = [uuid.uuid4() for _ in range(5)]
    expected = [{"S": str(id)} for id in loaded]

    dumped = typedef.dynamo_dump(loaded, context={"engine": engine})
    assert dumped == expected
    assert typedef.dynamo_load(dumped, context={"engine": engine}) == loaded
コード例 #2
0
def test_nested_output_actions_pass(action_type):
    """Any actions returned from _dump are nestable"""
    class AlwaysAction(String):
        def _dump(self, value, **kwargs):
            return action_type.new_action(value)

    typedef = List(AlwaysAction)
    typedef._dump(["foo"], context=None)

    typedef = Map(foo=AlwaysAction)
    typedef._dump({"foo": "f"}, context=None)
コード例 #3
0
def test_nested_output_actions_fail(action_type):
    """When the _dump function returns a non-nestable action the type raises"""
    class AlwaysAction(String):
        def _dump(self, value, **kwargs):
            return action_type.new_action(value)

    typedef = List(AlwaysAction)
    with pytest.raises(ValueError):
        typedef._dump(["foo"], context=None)

    typedef = Map(foo=AlwaysAction)
    with pytest.raises(ValueError):
        typedef._dump({"foo": "f"}, context=None)
コード例 #4
0
def test_list_path(key):
    """To support paths in condition expressions, __getitem__ must return another Type.  List only has one Type."""
    inner = UUID()
    typedef = List(inner)
    assert typedef[key] is inner
コード例 #5
0
    """single-value types without an explicit 'lack of value' sentinel should return None when given None"""
    type = typedef()
    context = {}

    assert type._load(None, context=context) is None
    assert type._load({typedef.backing_type: None}, context=context) is None
    assert type.dynamo_load(None, context=context) is None

    assert type._dump(None, context=context) is None
    assert type.dynamo_dump(None, context=context) is None


@pytest.mark.parametrize("typedef, default", [(Set(String), set()),
                                              (Set(Integer), set()),
                                              (Set(Binary), set()),
                                              (List(DateTime), list()),
                                              (DocumentType, {
                                                  "Rating": None,
                                                  "Stock": None,
                                                  "Description": {
                                                      "Heading": None,
                                                      "Body": None,
                                                      "Specifications": None
                                                  },
                                                  "Id": None,
                                                  "Updated": None
                                              })])
def test_load_none_vector_types(engine, typedef, default):
    """multi-value types return empty containers when given None"""
    engine.type_engine.register(DocumentType)
    engine.type_engine.bind()
コード例 #6
0
    assert type._load(None, context=context) is None
    assert type._load({typedef.backing_type: None}, context=context) is None
    assert type.dynamo_load(None, context=context) is None

    assert type._dump(None, context=context) == actions.wrap(None)
    assert type.dynamo_dump(None, context=context) is None


@pytest.mark.parametrize("typedef, default", [
    (String(), ""),
    (Binary(), b""),
    (Set(String), set()),
    (Set(Integer), set()),
    (Set(Binary), set()),
    (List(DateTime), list()),
    (DocumentType, {
        "Rating": None,
        "Stock": None,
        "Description": {
            "Heading": "",
            "Body": "",
            "Specifications": ""
        },
        "Id": None,
        "Updated": None
    }),
    (DynamicList(), []),
    (DynamicMap(), {}),
])
def test_load_none_vector_types(engine, typedef, default):
コード例 #7
0
    condition = c.is_(3)
    assert condition.operation == "=="
    assert condition.column is c
    assert condition.values == [3]

    condition = c.is_not(3)
    assert condition.operation == "!="
    assert condition.column is c
    assert condition.values == [3]


@pytest.mark.parametrize(
    "op, typedefs, args",
    [("begins_with", [
        Integer(),
        List(String),
        Map(s=String),
        Boolean(),
        Set(Integer),
        Set(Binary),
        Set(String)
    ], ("one-arg", )),
     ("contains", [Integer(), Boolean(), Map(s=String)], ("one-arg", )),
     ("between", [
         Set(String),
         Set(Binary),
         Set(String),
         List(String),
         Map(s=String),
         Boolean()
     ], ("first-arg", "second-arg"))])