Skip to content

Commit

Permalink
Use only active rules for transcription
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaniartefact committed Jul 12, 2024
1 parent 10fa987 commit bbc4bb2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/MCPClient/lib/clientScripts/transcribe_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def insert_file_into_database(
def fetch_rules_for(file_):
try:
format = FileFormatVersion.objects.get(file_uuid=file_)
return FPRule.objects.filter(
return FPRule.active.filter(
format=format.format_version, purpose="transcription"
)
except (FileFormatVersion.DoesNotExist, ValidationError):
Expand Down
66 changes: 66 additions & 0 deletions tests/MCPClient/test_transcribe_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,69 @@ def test_fetch_rules_for_derivatives(
).count()
== 1
)


@pytest.fixture
def command_disabled(tool, file):
return fprmodels.FPCommand.objects.create(
tool=tool,
description="Transcribe using Tesseract",
command_usage="transcription",
command="echo Hello",
script_type="bashScript",
output_location=file.currentlocation.decode(),
enabled=0,
)


@pytest.fixture
def disabled_fprule(format_version, command_disabled):
return fprmodels.FPRule.objects.create(
format=format_version,
command=command_disabled,
purpose="transcription",
enabled=0,
)


@pytest.mark.django_db
def test_main_if_fprule_is_disabled(file, task, disabled_fprule, file_format_version):
job = mock.Mock(spec=Job)

result = transcribe_file.main(job, task_uuid=task.taskuuid, file_uuid=file.uuid)

assert result == 0

assert job.write_output.mock_calls == []
assert (
models.Event.objects.filter(
file_uuid_id=file.uuid,
event_type="transcription",
event_outcome="transcribed",
event_outcome_detail="%SIPDirectory%objects/file.jpg",
).count()
== 0
)
assert (
models.File.objects.filter(
filegrpuse="original",
originallocation=file.originallocation,
currentlocation=file.currentlocation,
).count()
== 1
)
assert (
models.File.objects.filter(
filegrpuse="text/ocr",
originallocation=file.originallocation,
currentlocation=file.currentlocation,
).count()
== 0
)
assert (
models.Derivation.objects.filter(
event__event_type="transcription",
source_file_id=file.uuid,
).count()
== 0
)

0 comments on commit bbc4bb2

Please sign in to comment.