Skip to content

Commit

Permalink
Add filters for submission feed to transcription view (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed May 29, 2023
1 parent 0e8c2d2 commit e40bb0f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
35 changes: 35 additions & 0 deletions blossom/api/tests/test_transcriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,41 @@ def test_search_with_ordering_filter(
]
assert result_times == expected_times

@pytest.mark.parametrize(
"filter_str,value,expected_count",
[
("", "/r/boneappletea", 0),
("", "/r/BoneAppleTea", 2),
("__iexact", "/r/boneappletea", 2),
("__icontains", "/r/", 3),
],
)
def test_search_with_submission_feed_filter(
self, client: Client, filter_str: str, value: str, expected_count: int
) -> None:
"""Ensure that transcriptions can be filtered by the feed of their submission."""
client, headers, user = setup_user_client(client)

for idx, feed in enumerate(["/r/me_irl", "/r/BoneAppleTea", "/r/BoneAppleTea", None]):
submission = create_submission(id=idx + 100, feed=feed)
create_transcription(submission, user, id=idx + 200)

result = client.get(
reverse("transcription-list") + f"?submission__feed{filter_str}={value}",
content_type="application/json",
**headers,
)
assert result.status_code == status.HTTP_200_OK

sub_results = client.get(
reverse("submission-list") + f"?feed{filter_str}={value}",
content_type="application/json",
**headers,
)
print(filter_str, value, sub_results.json()["results"])

assert len(result.json()["results"]) == expected_count


class TestTranscriptionRandom:
"""Tests that validate the behavior of the Random Review process."""
Expand Down
2 changes: 1 addition & 1 deletion blossom/api/views/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class SubmissionViewSet(viewsets.ModelViewSet):
"content_url": ["exact", "isnull"],
"redis_id": ["exact", "isnull"],
"removed_from_queue": ["exact"],
"feed": ["exact", "isnull", "iexact"],
"feed": ["exact", "iexact", "icontains", "isnull"],
}
ordering_fields = [
"id",
Expand Down
1 change: 1 addition & 0 deletions blossom/api/views/transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class TranscriptionViewSet(viewsets.ModelViewSet):
filterset_fields = {
"id": ["exact"],
"submission": ["exact"],
"submission__feed": ["exact", "iexact", "icontains", "isnull"],
"author": ["exact"],
"original_id": ["exact", "isnull"],
"source": ["exact"],
Expand Down

0 comments on commit e40bb0f

Please sign in to comment.