Skip to content

Commit

Permalink
Fixed bug where OCR didn't work on an asset with an existing transcript
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuastegmaier committed Jan 14, 2025
1 parent 04eb13e commit eb81cbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
13 changes: 13 additions & 0 deletions concordia/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,25 @@ def test_generate_ocr_transcription(self, mock):
mock.reset_mock()

with patch("concordia.views.get_transcription_superseded") as superseded_mock:
# Test case if the trancription being replaced has already been superseded
superseded_mock.return_value = HttpResponse(status=409)
url = reverse("generate-ocr-transcription", kwargs={"asset_pk": asset2.pk})
response = self.client.post(url)
self.assertEqual(409, response.status_code)
self.assertTrue(superseded_mock.called)
self.assertFalse(mock.called)

# Test case if the transcription being replaced hasn't been superseded
superseded_mock.reset_mock()
superseded_mock.return_value = create_transcription(
asset=asset2, user=get_anonymous_user(), submitted=now()
)
url = reverse("generate-ocr-transcription", kwargs={"asset_pk": asset2.pk})
response = self.client.post(url)
self.assertEqual(201, response.status_code)
self.assertTrue(superseded_mock.called)
self.assertTrue(mock.called)

def test_project_detail_view(self):
"""
Test GET on route /campaigns/<slug-value> (campaign)
Expand Down
12 changes: 9 additions & 3 deletions concordia/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,10 +1631,16 @@ def generate_ocr_transcription(request, *, asset_pk):
language = request.POST.get("language", None)
superseded = get_transcription_superseded(asset, supersedes_pk)
if superseded:
return superseded
# If superseded is an HttpResponse, that means
# this transcription has already been superseded, so
# we won't run OCR and instead send back an error
# Otherwise, we just have thr transcription the OCR
# is gong to supersede, so we can continue
if isinstance(superseded, HttpResponse):
return superseded
else:
# This means this is the first transcription on this asset
# to enable undoing of the OCR transcription, we create
# This means this is the first transcription on this asset.
# To enable undoing of the OCR transcription, we create
# an empty transcription for the OCR transcription to supersede
superseded = Transcription(
asset=asset,
Expand Down

0 comments on commit eb81cbe

Please sign in to comment.