def test_rate_count_aggregation( self, client: Client, data: List[Dict[str, Union[str, int]]], url_additions: str, different_result: List[Dict], ) -> None: """Test if the number of transcriptions per day is aggregated correctly.""" client, headers, user = setup_user_client(client, id=123456) for obj in data: date = make_aware( datetime.strptime(obj.get("date"), "%Y-%m-%dT%H:%M:%SZ")) for _ in range(obj.get("count")): create_transcription( create_submission(completed_by=user, complete_time=date), user, create_time=date, ) if not url_additions: url_additions = "?completed_by=123456" else: url_additions += "&completed_by=123456" result = client.get( reverse("submission-rate") + url_additions, content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK rates = result.json()["results"] if different_result: assert rates == different_result else: assert rates == data
def test_search_with_ordering_filter( self, client: Client, ordering: str, create_times: List[datetime], expected_times: List[datetime], ) -> None: """Verify that listing items with specified orderings works correctly.""" client, headers, user = setup_user_client(client) for time in create_times: create_transcription(create_time=make_aware(time), submission=create_submission(), user=user) result = client.get( reverse("transcription-list") + f"?ordering={ordering}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK result_times = [ datetime.strptime(obj.get("create_time"), "%Y-%m-%dT%H:%M:%SZ") for obj in result.json()["results"] ] assert result_times == expected_times
def test_list_with_null_filters(self, client: Client, filter_str: str, result_count: int) -> None: """Verify that filtering for null works correctly.""" client, headers, user = setup_user_client(client, id=123) submission = create_submission(id=1) create_transcription( submission, user, id=2, original_id="abc", url="https://example.org", text="Test Transcription", ) create_transcription(submission, user, id=3, original_id=None, url=None, text=None) result = client.get( reverse("transcription-list") + f"?{filter_str}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == result_count
def test_is_returning_transcriber( self, client: Client, recent_gamma: int, total_gamma: int, expected: bool, ) -> None: """Test whether returning transcribers are determined correctly.""" # Mock both the total gamma with patch( "authentication.models.BlossomUser.gamma", new_callable=PropertyMock, return_value=total_gamma, ): # Mock the Slack client to catch the sent messages by the function under test. client, headers, user = setup_user_client(client) now = datetime.datetime.now(tz=pytz.UTC) # Create the recent transcriptions for i in range(0, recent_gamma): submission = create_submission( id=i + 100, claimed_by=user, completed_by=user, complete_time=now, ) create_transcription(submission, user, id=i + 100, create_time=now) assert _is_returning_transcriber(user) == expected
def test_time_frames( self, client: Client, time_frame: str, dates: List[datetime], results: List[Dict[str, Union[str, int]]], ) -> None: """Verify that the time_frame parameter properly changes the response.""" client, headers, user = setup_user_client(client, id=123456) for date in dates: create_transcription( create_submission(completed_by=user, complete_time=date), user, create_time=make_aware(date), ) result = client.get( reverse("submission-rate") + f"?time_frame={time_frame}&completed_by=123456", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK response = result.json() assert response["results"] == results
def test_get_transcribot_queue(self, client: Client) -> None: """Test that the OCR queue endpoint returns the correct data.""" client, headers, _ = setup_user_client(client) user_model = get_user_model() transcribot = user_model.objects.get(username="******") result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() assert len(result["data"]) == 0 # there are no posts to work on submission = create_submission(source="reddit") result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() # now there's a submission without a transcribot transcription assert len(result["data"]) == 0 create_transcription(submission, transcribot, original_id=None) result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() # now the submission has a transcribot entry assert len(result["data"]) == 1
def test_list_with_time_filters(self, client: Client) -> None: """Verify that the transcriptions can be filtered by time.""" client, headers, user = setup_user_client(client) dates = [ datetime(2021, 1, 1), datetime(2021, 2, 1), datetime(2021, 2, 3), datetime(2021, 5, 10), ] for date in dates: create_transcription(create_submission(), user, create_time=make_aware(date)) result = client.get( reverse("transcription-list") + "?create_time__gte=2021-02-01T00:00:00Z" + "&create_time__lte=2021-04-01T00:00:00Z", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == 2
def test_check_for_rank_up(self, client: Client, settings: SettingsWrapper) -> None: """Verify that a slack message fires when a volunteer ranks up.""" client, headers, user = setup_user_client(client) for iteration in range(24): create_submission(claimed_by=user, completed_by=user) # Mock the Slack client to catch the sent messages by the function under test. slack_client.chat_postMessage = MagicMock() submission = create_submission(claimed_by=user, original_id=25) # patch out transcription check with patch( "api.views.submission._should_check_transcription", return_value=False, ): result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps({ "username": user.username, "mod_override": "True" }), content_type="application/json", **headers, ) assert result.status_code == status.HTTP_201_CREATED slack_message = ( f"Congrats to {user.username} on achieving the rank of {user.get_rank()}!!" f" {submission.tor_url}") assert (call(channel=settings.SLACK_RANK_UP_CHANNEL, text=slack_message) == slack_client.chat_postMessage.call_args_list[0]) # now they do another transcription! submission = create_submission(claimed_by=user, original_id=26) create_transcription(submission, user) # now it shouldn't trigger on the next transcription # patch out transcription check old_count_of_slack_calls = len( slack_client.chat_postMessage.call_args_list) with patch( "api.views.submission._should_check_transcription", return_value=False, ): result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps({"username": user.username}), content_type="application/json", **headers, ) assert result.status_code == status.HTTP_201_CREATED # nothing fired, right? assert (len(slack_client.chat_postMessage.call_args_list) == old_count_of_slack_calls)
def test_heatmap_timezones(self, client: Client) -> None: """Test that the timezone is adjusted correctly, if specified.""" client, headers, user = setup_user_client(client, accepted_coc=True, id=123456) dates = [ # Thursday 14:03 h datetime(2020, 7, 16, 14, 3, 55), # Thursday 14:59 h datetime(2020, 7, 16, 14, 59, 55), # Sunday 15:10 h datetime(2021, 6, 20, 15, 10, 5), # Sunday 15:42 h datetime(2021, 6, 20, 15, 42, 10), # Sunday 16:05 h datetime(2021, 6, 20, 16, 5, 5), # Thursday 14:30 h datetime(2021, 6, 24, 14, 30, 30), ] for date in dates: create_transcription( create_submission(completed_by=user, complete_time=make_aware(date)), user, create_time=make_aware(date), ) # +01:30 offset utc_offset = 90 * 60 result = client.get( reverse("submission-heatmap") + f"?completed_by=123456&utc_offset={utc_offset}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK expected_heatmap = [ # Thursday 13:30 - 14:30 UTC {"day": 4, "hour": 15, "count": 1}, # Thursday 14:30 - 15:30 UTC {"day": 4, "hour": 16, "count": 2}, # Sunday 14:30 - 15:30 UTC {"day": 7, "hour": 16, "count": 1}, # Sunday 15:30 - 16:30 UTC {"day": 7, "hour": 17, "count": 2}, ] heatmap = result.json() assert heatmap == expected_heatmap
def test_find_completed(client: Client, url: str, expected: bool) -> None: """Verify that a completed posts can be found by its URLs.""" client, headers, user = setup_user_client(client, id=123, username="******") submission = create_submission( claimed_by=user, completed_by=user, url="https://reddit.com/r/antiwork/comments/q1tlcf/work_is_work/", tor_url= "https://reddit.com/r/TranscribersOfReddit/comments/q1tnhc/antiwork_image_work_is_work/", content_url="https://i.redd.it/upwchc4bqhr71.jpg", title="Work is work", ) transcription = create_transcription( id=555, submission=submission, user=user, url="https://reddit.com/r/antiwork/comments/q1tlcf/comment/hfgp814/", ) ocr_bot = create_user(id=333, username="******", is_bot=True) ocr = create_transcription( id=666, submission=submission, user=ocr_bot, url= "https://www.reddit.com/r/TranscribersOfReddit/comments/q1tnhc/comment/hfgp1gt/", ) result = client.get( reverse("find") + f"?url={url}", content_type="application/json", **headers, ) if expected: assert result.status_code == status.HTTP_200_OK actual = result.json() assert actual["submission"]["id"] == submission.id assert actual["author"]["id"] == user.id assert actual["transcription"]["id"] == transcription.id assert actual["ocr"]["id"] == ocr.id else: assert result.status_code == status.HTTP_404_NOT_FOUND
def test_search(self, client: Client) -> None: """Test whether only transcriptions of the provided Submission are returned.""" client, headers, user = setup_user_client(client) first_sub = create_submission() second_sub = create_submission(original_id="second_submission") transcription = create_transcription(first_sub, user) create_transcription(second_sub, user) result = client.get( reverse("transcription-search") + f"?submission_id={first_sub.id}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()) == 1 assert result.json()[0]["id"] == transcription.id
def test_removed_transcription_changes(self, client: Client) -> None: """Verify that a removed transcription is not sent to Slack.""" # Mock both the gamma property and the random.random function. with patch("authentication.models.BlossomUser.gamma", new_callable=PropertyMock) as mock: mock.return_value = 0 # Mock the Slack client to catch the sent messages by the function under test. slack_client.chat_postMessage = MagicMock() client, headers, user = setup_user_client(client) submission = create_submission(tor_url="asdf", claimed_by=user) create_transcription(submission, user, url=None, removed_from_reddit=True) result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps({"username": user.username}), content_type="application/json", **headers, ) assert result.status_code == status.HTTP_201_CREATED assert len(slack_client.chat_postMessage.call_args_list) == 1 # A new transcriber with a removed post should get sent. An existing one # shouldn't get forwarded since they should hopefully already know what # they're doing and we'll see one of their next (not removed) posts anyway. mock.return_value = 10 # reset the slack_client mock slack_client.chat_postMessage = MagicMock() # reset the submission submission.completed_by = None submission.complete_time = None submission.save() result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps({"username": user.username}), content_type="application/json", **headers, ) assert result.status_code == status.HTTP_201_CREATED assert len(slack_client.chat_postMessage.call_args_list) == 0
def test_rate_filtering( self, client: Client, ) -> None: """Verify that filters can be applied to the submissions.""" client, headers, user = setup_user_client(client, id=123456) dates = [ # Thursday 14 h datetime(2020, 7, 16, 14, 3, 55), # Thursday 14 h datetime(2020, 7, 16, 14, 59, 55), # Sunday 15 h datetime(2021, 6, 20, 15, 10, 5), # Sunday 15 h datetime(2021, 6, 20, 15, 42, 10), # Sunday 16 h datetime(2021, 6, 20, 16, 5, 5), # Thursday 14 h datetime(2021, 6, 24, 14, 30, 30), ] for date in dates: create_transcription( create_submission(completed_by=user, complete_time=date), user, create_time=make_aware(date), ) result = client.get( reverse("submission-rate") + "?time_frame=day&completed_by=123456" + "&complete_time__gte=2021-06-01T00:00:00Z" + "&complete_time__lte=2021-06-21T00:00:00Z", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK response = result.json() assert response["results"] == [ { "count": 3, "date": "2021-06-20T00:00:00Z" }, ]
def test_heatmap_filtering(self, client: Client) -> None: """Verify that filters can be applied to the submissions.""" client, headers, user = setup_user_client(client, accepted_coc=True, id=123456) dates = [ # Thursday 14 h datetime(2020, 7, 16, 14, 3, 55), # Thursday 14 h datetime(2020, 7, 16, 14, 59, 55), # Sunday 15 h datetime(2021, 6, 20, 15, 10, 5), # Sunday 15 h datetime(2021, 6, 20, 15, 42, 10), # Sunday 16 h datetime(2021, 6, 20, 16, 5, 5), # Thursday 14 h datetime(2021, 6, 24, 14, 30, 30), ] for date in dates: create_transcription( create_submission(completed_by=user, complete_time=make_aware(date)), user, create_time=make_aware(date), ) result = client.get( reverse("submission-heatmap") + "?complete_time__gte=2021-06-19T00:00:00Z" + "&complete_time__lte=2021-06-21T00:00:00Z", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK expected_heatmap = [ # Sunday 15 h {"day": 7, "hour": 15, "count": 2}, # Sunday 16 h {"day": 7, "hour": 16, "count": 1}, ] heatmap = result.json() assert heatmap == expected_heatmap
def test_heatmap_aggregation(self, client: Client) -> None: """Test that transcriptions in the same slot are aggregated.""" client, headers, user = setup_user_client(client, accepted_coc=True, id=123456) dates = [ # Thursday 14 h datetime(2020, 7, 16, 14, 3, 55), # Thursday 14 h datetime(2020, 7, 16, 14, 59, 55), # Sunday 15 h datetime(2021, 6, 20, 15, 10, 5), # Sunday 15 h datetime(2021, 6, 20, 15, 42, 10), # Sunday 16 h datetime(2021, 6, 20, 16, 5, 5), # Thursday 14 h datetime(2021, 6, 24, 14, 30, 30), ] for date in dates: create_transcription( create_submission(completed_by=user, complete_time=make_aware(date)), user, create_time=make_aware(date), ) result = client.get( reverse("submission-heatmap") + "?completed_by=123456", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK expected_heatmap = [ # Thursday 14 h {"day": 4, "hour": 14, "count": 3}, # Sunday 15 h {"day": 7, "hour": 15, "count": 2}, # Sunday 16 h {"day": 7, "hour": 16, "count": 1}, ] heatmap = result.json() assert heatmap == expected_heatmap
def test_find_by_submission_url(client: Client, url: str, url_type: str, expected: bool) -> None: """Verify that a submission is found by its submission URL.""" client, headers, user = setup_user_client(client, id=123, username="******") submission = create_submission( claimed_by=user, completed_by=user, url="https://reddit.com/r/antiwork/comments/q1tlcf/work_is_work/", tor_url= "https://reddit.com/r/TranscribersOfReddit/comments/q1tnhc/antiwork_image_work_is_work/", content_url="https://i.redd.it/upwchc4bqhr71.jpg", title="Work is work", ) transcription = create_transcription( id=555, submission=submission, user=user, url="https://reddit.com/r/antiwork/comments/q1tlcf/comment/hfgp814/", ) ocr_bot = create_user(id=333, username="******", is_bot=True) ocr = create_transcription( id=666, submission=submission, user=ocr_bot, url= "https://www.reddit.com/r/TranscribersOfReddit/comments/q1tnhc/comment/hfgp1gt/", ) actual = find_by_submission_url(url, url_type) if expected: assert actual is not None assert actual["submission"] == submission assert actual["author"] == user assert actual["transcription"] == transcription assert actual["ocr"] == ocr else: assert actual is None
def test_rate_timezones( self, client: Client, ) -> None: """Verify that the timezone is applied correctly, if specified.""" client, headers, user = setup_user_client(client, id=123456) dates = [ # 2020-07-16 23:00 UTC datetime(2020, 7, 16, 23), # 2020-07-16 22:00 UTC datetime(2020, 7, 16, 22), ] for date in dates: create_transcription( create_submission(completed_by=user, complete_time=date), user, create_time=make_aware(date), ) # +01:30 offset utc_offset = 90 * 60 result = client.get( reverse("submission-rate") + "?time_frame=day&completed_by=123456" + f"&utc_offset={utc_offset}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK response = result.json() assert response["results"] == [ { "count": 1, "date": "2020-07-16T00:00:00+01:30" }, { "count": 1, "date": "2020-07-17T00:00:00+01:30" }, ]
def test_done(self, client: Client) -> None: """Test whether done process works correctly when invoked correctly.""" client, headers, user = setup_user_client(client) submission = create_submission(claimed_by=user) create_transcription(submission, user) data = {"username": user.username} result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps(data), content_type="application/json", **headers, ) submission.refresh_from_db() assert result.status_code == status.HTTP_201_CREATED assert submission.claimed_by == user assert submission.completed_by == user assert result.json()["original_id"] == submission.original_id
def test_done_random_checks( self, client: Client, settings: SettingsWrapper, probability: float, gamma: int, message: bool, tor_url: [str, None], trans_url: [str, None], ) -> None: """Test whether the random checks for the done process are invoked correctly.""" # Mock both the gamma property and the random.random function. with patch("authentication.models.BlossomUser.gamma", new_callable=PropertyMock) as mock, patch( "api.views.submission._is_returning_transcriber", return_value=False), patch("random.random", lambda: probability): mock.return_value = gamma # Mock the Slack client to catch the sent messages by the function under test. slack_client.chat_postMessage = MagicMock() client, headers, user = setup_user_client(client) submission = create_submission(tor_url=tor_url, claimed_by=user) create_transcription(submission, user, url=trans_url) result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps({"username": user.username}), content_type="application/json", **headers, ) slack_message = ( f"Please check the following transcription of u/{user.username}: " f"{trans_url if trans_url else tor_url}.") assert result.status_code == status.HTTP_201_CREATED if message: assert (call( channel=settings.SLACK_TRANSCRIPTION_CHECK_CHANNEL, text=slack_message, ) in slack_client.chat_postMessage.call_args_list) else: assert slack_client.chat_postMessage.call_count == 0
def test_random(self, client: Client) -> None: """Test whether a transcription is returned when available.""" client, headers, user = setup_user_client(client) submission = create_submission() transcription = create_transcription(submission, user) result = client.get(reverse("transcription-review-random"), **headers) assert result.status_code == status.HTTP_200_OK assert result.json() assert result.json()["original_id"] == transcription.original_id
def test_yeet_also_removes_linked_transcription(self, client: Client) -> None: """Verify that a linked transcription also gets yeeted.""" client, headers, user = setup_user_client(client) submission = create_submission(original_id=str(uuid4()), completed_by=user) create_transcription(submission, user) assert Submission.objects.count() == 1 assert Transcription.objects.count() == 1 data = {"username": user.username} client.post(reverse("submission-yeet"), json.dumps(data), content_type="application/json", **headers) assert Submission.objects.count() == 0 assert Transcription.objects.count() == 0
def test_list(self, client: Client) -> None: """Test that the primary API page for transcriptions works correctly.""" client, headers, user = setup_user_client(client) submission = create_submission() result = client.get(reverse("transcription-list"), content_type="application/json", **headers) assert result.status_code == status.HTTP_200_OK assert result.json()["count"] == 0 create_transcription(submission, user) result = client.get(reverse("transcription-list"), content_type="application/json", **headers) assert result.status_code == status.HTTP_200_OK assert result.json()["count"] == 1 assert result.json()["results"][0]["id"] == 1
def test_list_with_contains_filters(self, client: Client, filter_str: str, result_count: int) -> None: """Test whether the transcription text can be searched.""" client, headers, user = setup_user_client(client, id=123) submission = create_submission(id=1) create_transcription( submission, user, id=2, text="This is a very interesting text and such.", ) create_transcription( submission, user, id=3, text="A text is a form of literature.", ) create_transcription( submission, user, id=4, text="Bla bla bla bla.", ) result = client.get( reverse("transcription-list") + f"?{filter_str}", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == result_count
def test_transcribot_limit_param(self, client: Client) -> None: """Verify that adding the `limit` QSP modifies the results.""" client, headers, _ = setup_user_client(client) user_model = get_user_model() transcribot = user_model.objects.get(username="******") submission1 = create_submission(source="reddit", original_id="A") submission2 = create_submission(source="reddit", original_id="B") submission3 = create_submission(source="reddit", original_id="C") create_transcription(submission1, transcribot, original_id=None) create_transcription(submission2, transcribot, original_id=None) create_transcription(submission3, transcribot, original_id=None) result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit&limit=none", content_type="application/json", **headers, ).json() assert len(result["data"]) == 3 result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit&limit=1", content_type="application/json", **headers, ).json() assert len(result["data"]) == 1 assert result["data"][0]["id"] == submission1.id
def test_pagination(self, client: Client) -> None: """Verify that pagination parameters properly change response.""" client, headers, user = setup_user_client(client, id=123456) for day in range(1, 4): date = make_aware(datetime(2021, 6, day)) create_transcription( create_submission(completed_by=user, complete_time=date), user, create_time=date, ) result = client.get( reverse("submission-rate") + "?page_size=1&page=2&completed_by=123456", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK response = result.json() assert len(response["results"]) == 1 assert response["results"][0]["date"] == "2021-06-02T00:00:00Z" assert response["previous"] is not None assert response["next"] is not None
def test_done_no_coc(self, client: Client) -> None: """# noqa Test that a submission isn't marked as done when the CoC hasn't been accepted. """ client, headers, user = setup_user_client(client) submission = create_submission(claimed_by=user) user.accepted_coc = False user.save() create_transcription(submission, user) data = {"username": user.username} result = client.patch( reverse("submission-done", args=[submission.id]), json.dumps(data), content_type="application/json", **headers, ) submission.refresh_from_db() assert result.status_code == status.HTTP_403_FORBIDDEN assert submission.claimed_by == user assert submission.completed_by is None
def test_normal_transcriptions_dont_affect_ocr_queue( self, client: Client) -> None: """Verify that a human-completed transcription doesn't affect the OCR queue.""" client, headers, user = setup_user_client(client) submission = create_submission(source="reddit") result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() assert len(result["data"]) == 0 create_transcription(submission, user) result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() # there should be no change to the OCR queue assert len(result["data"]) == 0
def test_list_with_filters(self, client: Client) -> None: """Verify that listing all submissions works correctly.""" client, headers, user = setup_user_client(client) aaa, _ = Source.objects.get_or_create(name="AAA") bbb, _ = Source.objects.get_or_create(name="BBB") submission = create_submission() create_transcription(submission, user, source=aaa) create_transcription(submission, user, source=aaa) create_transcription(submission, user, source=bbb) create_transcription(submission, user, source=bbb) result = client.get(reverse("transcription-list"), content_type="application/json", **headers) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == 4 result = client.get( reverse("transcription-list") + "?source=AAA", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == 2 assert "AAA" in result.json()["results"][0][ "source"] # it will be a full link result = client.get( reverse("transcription-list") + "?source=AAA&id=1", content_type="application/json", **headers, ) assert result.status_code == status.HTTP_200_OK assert len(result.json()["results"]) == 1 assert "AAA" in result.json()["results"][0][ "source"] # it will be a full link assert result.json()["results"][0]["id"] == 1
def test_completed_ocr_transcriptions(self, client: Client) -> None: """Test that a completed transcription removes the submission from the queue.""" client, headers, _ = setup_user_client(client) user_model = get_user_model() transcribot = user_model.objects.get(username="******") submission = create_submission(source="reddit") result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() assert len(result["data"]) == 0 transcription = create_transcription(submission, transcribot, original_id=None) result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() # now there's a transcription that needs work assert len(result["data"]) == 1 # transcribot works on it transcription.original_id = "AAA" transcription.save() result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit", content_type="application/json", **headers, ).json() # Queue goes back to 0. assert len(result["data"]) == 0
def test_verify_no_removed_posts(self, client: Client) -> None: """Verify that a post removed from the queue is not sent to transcribot.""" client, headers, _ = setup_user_client(client) user_model = get_user_model() transcribot = user_model.objects.get(username="******") submission1 = create_submission(source="reddit", original_id="A") submission2 = create_submission(source="reddit", original_id="B", removed_from_queue=True) submission3 = create_submission(source="reddit", original_id="C") create_transcription(submission1, transcribot, original_id=None) create_transcription(submission2, transcribot, original_id=None) create_transcription(submission3, transcribot, original_id=None) result = client.get( reverse("submission-get-transcribot-queue") + "?source=reddit&limit=none", content_type="application/json", **headers, ).json() assert len(result["data"]) == 2