Created
July 6, 2020 18:08
-
-
Save ceberly/2ebc235fd7c29c797a278d23d9ea766d to your computer and use it in GitHub Desktop.
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
# /localhost/query?terms=["a", "b", "c"]&limit=10&offset=20&sort="name"&sort_order="asc" | |
def query_request(params): | |
limit = params.get("limit", None) | |
offset = params.get("offset", 0) | |
sort_order = params.get("sort_order", "asc") | |
sort = params.get("sort", None) | |
terms = params.get("terms", []) | |
# do validation of things like empty terms, | |
# nonsense sort order ... usually inline. | |
# Can fail and should result in http errors | |
validate(terms, sort, sort_order, limit, offset) | |
# can fail in a number of ways depending on | |
# the request and also fail with http errors | |
return do_query(terms, sort, sort_order, limit, offset) | |
assert(query_request(), "error message")) | |
assert(query_request({"terms": "blah"}, "result1")) | |
assert(query_request({"terms": ["blah1", "blah2"]}, "result2")) | |
assert(query_request({"terms": "blah", "limit": 4}, "result3")) | |
assert(query_request({"terms": ["blah1", "blah2"], "limit": 4}, "result4")) | |
# and so on forever |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment