Beispiel #1
0
def test_search_projection_includes_non_projected_column(model, index):
    """Specific column names exist.

    Table, non-strict LSI, and indexes that project all columns will succeed; the rest fail."""
    should_succeed = False
    # Table searches always include all columns
    if index is None:
        should_succeed = True
    elif isinstance(
            index,
            LocalSecondaryIndex) and index.projection["strict"] is False:
        should_succeed = True
    elif index.projection["mode"] == "all":
        should_succeed = True

    projection = [model.model_hash, model.not_projected]

    if should_succeed:
        projected = validate_search_projection(model,
                                               index,
                                               projection=projection)
        assert projected == [model.model_hash, model.not_projected]

    else:
        with pytest.raises(InvalidSearch):
            validate_search_projection(model, index, projection=projection)
Beispiel #2
0
def test_search_projection_unknown_string(model, index):
    """Don't confuse a string for an iterable list.
    Users can be explicit with list("string") if their column names are all single-characters
    """

    with pytest.raises(InvalidSearch):
        validate_search_projection(model, index, projection="keys")
Beispiel #3
0
def test_search_projection_unknown_column(model, index):
    with pytest.raises(InvalidSearch):
        validate_search_projection(model,
                                   index,
                                   projection=["model_hash", "unknown"])
    with pytest.raises(InvalidSearch):
        validate_search_projection(model,
                                   index,
                                   projection=["model_hash", None])
Beispiel #4
0
def test_search_projection_converts_strings():
    """This doesn't need the full matrix of model/index combinations.

    Simply checks that the user can pass strings and get columns"""
    model, index = model_for()
    projection = ["model_hash"]
    expected = [model.model_hash]
    assert validate_search_projection(model, index, projection) == expected
Beispiel #5
0
def test_search_projection_all(model, index):
    projected = validate_search_projection(model, index, projection="all")
    expected = (index or model.Meta).projection["included"]
    assert projected == expected
Beispiel #6
0
def test_search_projection_is_count(model, index):
    assert validate_search_projection(model, index, projection="count") is None
Beispiel #7
0
def test_search_projection_is_required(model, index):
    """Test a missing projection, and an empty list of column names"""
    with pytest.raises(InvalidSearch):
        validate_search_projection(model, index, projection=None)
    with pytest.raises(InvalidSearch):
        validate_search_projection(model, index, projection=list())