diff --git a/src/documents/tests/test_document_model.py b/src/documents/tests/test_document_model.py index 57486a757..8a58f4b13 100644 --- a/src/documents/tests/test_document_model.py +++ b/src/documents/tests/test_document_model.py @@ -156,6 +156,46 @@ class TestDocument(TestCase): ) self.assertEqual(doc.get_public_filename(), "2020-12-25 test") + def test_suggestion_content_uses_latest_version_content_for_root_documents( + self, + ) -> None: + root = Document.objects.create( + title="root", + checksum="root", + mime_type="application/pdf", + content="outdated root content", + ) + version = Document.objects.create( + title="v1", + checksum="v1", + mime_type="application/pdf", + root_document=root, + content="latest version content", + ) + + self.assertEqual(root.suggestion_content, version.content) + + def test_content_length_is_per_document_row_for_versions(self) -> None: + root = Document.objects.create( + title="root", + checksum="root", + mime_type="application/pdf", + content="abc", + ) + version = Document.objects.create( + title="v1", + checksum="v1", + mime_type="application/pdf", + root_document=root, + content="abcdefgh", + ) + + root.refresh_from_db() + version.refresh_from_db() + + self.assertEqual(root.content_length, 3) + self.assertEqual(version.content_length, 8) + def test_suggestion_content() -> None: """ diff --git a/src/documents/tests/test_matchables.py b/src/documents/tests/test_matchables.py index 04ff3f6d3..e038bf786 100644 --- a/src/documents/tests/test_matchables.py +++ b/src/documents/tests/test_matchables.py @@ -48,6 +48,52 @@ class _TestMatchingBase(TestCase): class TestMatching(_TestMatchingBase): + def test_matches_uses_latest_version_content_for_root_documents(self) -> None: + root = Document.objects.create( + title="root", + checksum="root", + mime_type="application/pdf", + content="root content without token", + ) + Document.objects.create( + title="v1", + checksum="v1", + mime_type="application/pdf", + root_document=root, + content="latest version contains keyword", + ) + tag = Tag.objects.create( + name="tag", + match="keyword", + matching_algorithm=Tag.MATCH_ANY, + ) + + self.assertTrue(matching.matches(tag, root)) + + def test_matches_does_not_fall_back_to_root_content_when_version_exists( + self, + ) -> None: + root = Document.objects.create( + title="root", + checksum="root", + mime_type="application/pdf", + content="root contains keyword", + ) + Document.objects.create( + title="v1", + checksum="v1", + mime_type="application/pdf", + root_document=root, + content="latest version without token", + ) + tag = Tag.objects.create( + name="tag", + match="keyword", + matching_algorithm=Tag.MATCH_ANY, + ) + + self.assertFalse(matching.matches(tag, root)) + def test_match_none(self) -> None: self._test_matching( "",