Skip to content

Commit

Permalink
Extend test coverage of normalize script
Browse files Browse the repository at this point in the history
  • Loading branch information
replaceafill committed Aug 10, 2024
1 parent 501dda5 commit 6459e37
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 17 deletions.
17 changes: 10 additions & 7 deletions src/MCPClient/lib/clientScripts/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ def main(job, opts):
derivatives = Derivation.objects.filter(
source_file=file_, derived_file__filegrpuse=opts.purpose
)
derivatives_to_delete = []
for derivative in derivatives:
derivatives_to_delete.append(derivative.id)
job.print_output(
opts.purpose,
"derivative",
Expand All @@ -389,7 +391,8 @@ def main(job, opts):
databaseFunctions.insertIntoEvents(
fileUUID=derivative.derived_file_id, eventType="deletion"
)
derivatives.delete()
if derivatives_to_delete:
Derivation.objects.filter(id__in=derivatives_to_delete).delete()

# If a file has been manually normalized for this purpose, skip it
manually_normalized_file = check_manual_normalization(job, opts)
Expand All @@ -412,16 +415,16 @@ def main(job, opts):

do_fallback = False
try:
format_id = FileFormatVersion.objects.get(file_uuid=opts.file_uuid)
file_format_version = FileFormatVersion.objects.get(file_uuid=opts.file_uuid)
except (FileFormatVersion.DoesNotExist, ValidationError):
format_id = None
file_format_version = None

# Look up the normalization command in the FPR
if format_id:
job.print_output("File format:", format_id.format_version)
if file_format_version:
job.print_output("File format:", file_format_version.format_version)
try:
rule = FPRule.active.get(
format=format_id.format_version, purpose=opts.purpose
format=file_format_version.format_version, purpose=opts.purpose
)
except FPRule.DoesNotExist:
if (
Expand All @@ -434,7 +437,7 @@ def main(job, opts):
do_fallback = True

# Try with default rule if no format_id or rule was found
if format_id is None or do_fallback:
if file_format_version is None or do_fallback:
try:
rule = get_default_rule(opts.purpose)
job.print_output(
Expand Down
10 changes: 0 additions & 10 deletions src/MCPClient/lib/clientScripts/transcoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,9 @@
#
# You should have received a copy of the GNU General Public License
# along with Archivematica. If not, see <http://www.gnu.org/licenses/>.
# archivematicaCommon
from django.db.models import F
from executeOrRunSubProcess import executeOrRun

# dashboard


def toStrFromUnicode(inputString, encoding="utf-8"):
"""Converts to str, if it's unicode input type."""
if isinstance(inputString, str):
inputString = inputString.encode(encoding)
return inputString


class Command:
def __init__(self, job, command, replacement_dict, on_success=None, opts=None):
Expand Down
16 changes: 16 additions & 0 deletions tests/MCPClient/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ def fprule_preservation(fprule: fprmodels.FPRule) -> fprmodels.FPRule:
return fprule


@pytest.fixture
def fprule_thumbnail(fprule: fprmodels.FPRule) -> fprmodels.FPRule:
fprule.purpose = fprmodels.FPRule.THUMBNAIL
fprule.save()

return fprule


@pytest.fixture
def fprule_access(fprule: fprmodels.FPRule) -> fprmodels.FPRule:
fprule.purpose = fprmodels.FPRule.ACCESS
fprule.save()

return fprule


@pytest.fixture
def transfer_file(transfer: models.Transfer) -> models.File:
location = b"%transferDirectory%objects/file.mp3"
Expand Down
Loading

0 comments on commit 6459e37

Please sign in to comment.