Skip to content

Commit

Permalink
Bug 1902029 - Search input criteria of 12-40 characters is too restri…
Browse files Browse the repository at this point in the history
…ctive (#8258)

* Add new field author_contains to PushViewSet

* Add iexact to the existing author param

* Add test coverage
  • Loading branch information
beatrice-acasandrei authored Nov 15, 2024
1 parent b2231d1 commit dfa4b04
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
65 changes: 65 additions & 0 deletions tests/webapp/api/test_push_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ def test_push_author(client, test_repository):
assert len(results) == 2 # would have 3 if filter not applied
assert set([result["id"] for result in results]) == set([1, 2])

# iexact looks for a case-insensitive match
resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "[email protected]"
)
assert resp.status_code == 200

results = resp.json()["results"]
assert len(results) == 2 # would have 3 if filter not applied
assert set([result["id"] for result in results]) == set([1, 2])

resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "[email protected]"
)
Expand All @@ -299,6 +309,61 @@ def test_push_author(client, test_repository):
assert len(results) == 2 # would have 3 if filter not applied
assert set([result["id"] for result in results]) == set([1, 2])

# iexact looks for a case-insensitive match
resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "[email protected]"
)
assert resp.status_code == 200

results = resp.json()["results"]
assert len(results) == 2 # would have 3 if filter not applied
assert set([result["id"] for result in results]) == set([1, 2])


def test_push_author_contains(client, test_repository):
"""
test the author parameter
"""
for revision, author in [
("1234abcd", "[email protected]"),
("2234abcd", "[email protected]"),
("3234abcd", "[email protected]"),
]:
Push.objects.create(
repository=test_repository,
revision=revision,
author=author,
time=datetime.datetime.now(),
)

# icontains - case-insensitive containment test
resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "?author_contains=fOo"
)
assert resp.status_code == 200

results = resp.json()["results"]
assert len(results) == 2
assert set([result["id"] for result in results]) == set([1, 2])

resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "?author_contains=foO2"
)
assert resp.status_code == 200

results = resp.json()["results"]
assert len(results) == 1
assert results[0]["id"] == 2

resp = client.get(
reverse("push-list", kwargs={"project": test_repository.name}) + "?author_contains=qux"
)
assert resp.status_code == 200

results = resp.json()["results"]
assert len(results) == 1
assert results[0]["id"] == 3


def test_push_reviewbot(client, test_repository):
"""
Expand Down
8 changes: 6 additions & 2 deletions treeherder/webapp/api/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,13 @@ def list(self, request, project):
if author:
if author.startswith("-"):
author = author[1::]
pushes = pushes.exclude(author=author)
pushes = pushes.exclude(author__iexact=author)
else:
pushes = pushes.filter(author=author)
pushes = pushes.filter(author__iexact=author)

author_contains = filter_params.get("author_contains")
if author_contains:
pushes = pushes.filter(author__icontains=author_contains)

if filter_params.get("hide_reviewbot_pushes") == "true":
pushes = pushes.exclude(author="reviewbot")
Expand Down

0 comments on commit dfa4b04

Please sign in to comment.