diff --git a/tests/webapp/api/test_push_api.py b/tests/webapp/api/test_push_api.py index ea2b41d04..5b82f0b8b 100644 --- a/tests/webapp/api/test_push_api.py +++ b/tests/webapp/api/test_push_api.py @@ -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}) + "?author=FoO@bar.com" + ) + 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}) + "?author=foo2@bar.com" ) @@ -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}) + "?author=-FOo2@bar.com" + ) + 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", "foo@bar.com"), + ("2234abcd", "foo2@bar.com"), + ("3234abcd", "qux@bar.com"), + ]: + 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): """ diff --git a/treeherder/webapp/api/push.py b/treeherder/webapp/api/push.py index 78b4ca1c2..f523c33f5 100644 --- a/treeherder/webapp/api/push.py +++ b/treeherder/webapp/api/push.py @@ -155,9 +155,13 @@ class PushViewSet(viewsets.ViewSet): 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")