Bug 1902029 - Search input criteria of 12-40 characters is too restrictive (#8258)

* Add new field author_contains to PushViewSet

* Add iexact to the existing author param

* Add test coverage
This commit is contained in:
beatrice-acasandrei 2024-11-15 12:09:13 +02:00 коммит произвёл GitHub
Родитель b2231d1b39
Коммит dfa4b04f55
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 71 добавлений и 2 удалений

Просмотреть файл

@ -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):
"""

Просмотреть файл

@ -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")