Skip to content

Commit

Permalink
ensure is_finished and is_success are False if no associated files
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimpe committed Oct 11, 2024
1 parent 18690e8 commit aed94c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tdrs-backend/tdpservice/search_indexes/models/reparse_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ class Meta:
@property
def is_finished(self):
"""Return True if all associated ReparseFileMeta objects are finished."""
return all([r.finished for r in self.reparse_file_metas.all()])
if self.num_files > 0:
return all([r.finished for r in self.reparse_file_metas.all()])
return False

@property
def is_success(self):
"""Return True if all associated ReparseFileMeta objects are successful."""
return all([r.success for r in self.reparse_file_metas.all()])
if self.is_finished:
return all([r.success for r in self.reparse_file_metas.all()])
return False

@property
def finished_at(self):
Expand Down
22 changes: 22 additions & 0 deletions tdrs-backend/tdpservice/search_indexes/test/test_reparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,25 @@ def test_mm_file_counts_match(big_file):
fm.finished = True
fm.save()
assert ReparseMeta.file_counts_match(meta_model) is True

@pytest.mark.django_db()
def test_reparse_finished_success_false_before_file_queue(big_file):
meta_model = ReparseMeta.objects.create()
assert meta_model.is_finished is False
assert meta_model.is_success is False

big_file.reparses.add(meta_model)
big_file.save()
assert meta_model.is_finished is False
assert meta_model.is_success is False

fm = ReparseFileMeta.objects.get(data_file_id=big_file.pk, reparse_meta_id=meta_model.pk)
fm.finished = True
fm.save()
assert meta_model.is_finished is True
assert meta_model.is_success is False

fm.success = True
fm.save()
assert meta_model.is_finished is True
assert meta_model.is_success is True

0 comments on commit aed94c4

Please sign in to comment.