Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(misc): add unit tests #237

Merged
merged 2 commits into from
Aug 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions indexd/index/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ def get_index():
except ValueError as err:
raise UserError("limit must be an integer")

if limit <= 0 or limit > 1024:
raise UserError("limit must be between 1 and 1024")
if limit < 0 or limit > 1024:
raise UserError("limit must be between 0 and 1024")

size = flask.request.args.get("size")
try:
Expand Down Expand Up @@ -108,9 +108,6 @@ def get_index():
except ValueError:
raise UserError("urls_metadata must be a valid json string")

if limit < 0 or limit > 1024:
raise UserError("limit must be between 0 and 1024")

negate_params = flask.request.args.get("negate_params")
if negate_params:
try:
Expand Down
22 changes: 22 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@ def test_index_list_with_params_negate(client, user):
assert rec_5["did"] in ids


def test_index_list_invalid_param(client):
# test 400 when limit > 1024
res = client.get("/index/?limit=1025")
assert res.status_code == 400

# test 400 when limit < 0
res = client.get("/index/?limit=-1")
assert res.status_code == 400

# test 400 when limit not int
res = client.get("/index/?limit=string")
assert res.status_code == 400

# test 400 when size < 0
res = client.get("/index/?size=-1")
assert res.status_code == 400

# test 400 when size not int
res = client.get("/index/?size=string")
assert res.status_code == 400


def test_negate_filter_file_name(client, user):
# post two records of different file name
data1 = get_doc()
Expand Down