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)
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")
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])
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
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
def test_search_projection_is_count(model, index): assert validate_search_projection(model, index, projection="count") is None
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())