Example #1
0
def test_delete_atomic_condition(engine, session):
    user = User(id="user_id", email="*****@*****.**")

    # Tell the tracking system the user's id and email were saved to DynamoDB
    object_saved.send(engine, engine=engine, obj=user)

    expected = {
        "ConditionExpression": "((#n0 = :v1) AND (#n2 = :v3) AND (#n4 = :v5))",
        "ExpressionAttributeValues": {
            ":v1": {
                "S": "foo"
            },
            ":v3": {
                "S": "*****@*****.**"
            },
            ":v5": {
                "S": user.id
            }
        },
        "ExpressionAttributeNames": {
            "#n0": "name",
            "#n2": "email",
            "#n4": "id"
        },
        "Key": {
            "id": {
                "S": user.id
            }
        },
        "TableName": "User"
    }
    engine.delete(user, condition=User.name.is_("foo"), atomic=True)
    session.delete_item.assert_called_once_with(expected)
Example #2
0
def test_delete_atomic(engine, session):
    user = User(id="user_id")

    # Tell the tracking system the user's id was saved to DynamoDB
    object_saved.send(engine, engine=engine, obj=user)

    expected = {
        "ConditionExpression": "(#n0 = :v1)",
        "ExpressionAttributeValues": {
            ":v1": {
                "S": user.id
            }
        },
        "TableName": "User",
        "Key": {
            "id": {
                "S": user.id
            }
        },
        "ExpressionAttributeNames": {
            "#n0": "id"
        }
    }
    engine.delete(user, atomic=True)
    session.delete_item.assert_called_once_with(expected)
Example #3
0
def test_save_atomic_condition(engine, session):
    user = User(id="user_id")
    # Tell the tracking system the user's id was saved to DynamoDB
    object_saved.send(engine, engine=engine, obj=user)
    # Mutate a field; part of the update but not an expected condition
    user.name = "new_foo"
    # Condition on the mutated field with a different value
    condition = User.name == "expect_foo"

    expected = {
        "ConditionExpression": "((#n0 = :v1) AND (#n2 = :v3))",
        "ExpressionAttributeNames": {"#n0": "name", "#n2": "id"},
        "ExpressionAttributeValues": {
            ":v1": {"S": "expect_foo"},
            ":v3": {"S": user.id},
            ":v4": {"S": "new_foo"}},
        "Key": {"id": {"S": user.id}},
        "TableName": "User",
        "UpdateExpression": "SET #n0=:v4"
    }
    engine.save(user, condition=condition, atomic=True)
    session.save_item.assert_called_once_with(expected)