diff --git a/src/documents/management/commands/document_fuzzy_match.py b/src/documents/management/commands/document_fuzzy_match.py index 9e01ff1b0..5eebeb172 100644 --- a/src/documents/management/commands/document_fuzzy_match.py +++ b/src/documents/management/commands/document_fuzzy_match.py @@ -125,14 +125,14 @@ class Command(MultiProcessMixin, ProgressBarMixin, BaseCommand): messages.append( self.style.NOTICE( f"Document {result.doc_one_pk} fuzzy match" - f" to {result.doc_two_pk} (confidence {result.ratio:.3f})", + f" to {result.doc_two_pk} (confidence {result.ratio:.3f})\n", ), ) maybe_delete_ids.append(result.doc_two_pk) if len(messages) == 0: messages.append( - self.style.SUCCESS("No matches found"), + self.style.SUCCESS("No matches found\n"), ) self.stdout.writelines( messages, diff --git a/src/documents/tests/test_management_fuzzy.py b/src/documents/tests/test_management_fuzzy.py index 7cc1f265e..2d7d3735a 100644 --- a/src/documents/tests/test_management_fuzzy.py +++ b/src/documents/tests/test_management_fuzzy.py @@ -87,7 +87,7 @@ class TestFuzzyMatchCommand(TestCase): filename="other_test.pdf", ) stdout, _ = self.call_command() - self.assertEqual(stdout, "No matches found\n") + self.assertIn("No matches found", stdout) def test_with_matches(self): """ @@ -116,7 +116,7 @@ class TestFuzzyMatchCommand(TestCase): filename="other_test.pdf", ) stdout, _ = self.call_command("--processes", "1") - self.assertRegex(stdout, self.MSG_REGEX + "\n") + self.assertRegex(stdout, self.MSG_REGEX) def test_with_3_matches(self): """ @@ -152,11 +152,10 @@ class TestFuzzyMatchCommand(TestCase): filename="final_test.pdf", ) stdout, _ = self.call_command() - lines = [x.strip() for x in stdout.split("\n") if len(x.strip())] + lines = [x.strip() for x in stdout.splitlines() if x.strip()] self.assertEqual(len(lines), 3) - self.assertRegex(lines[0], self.MSG_REGEX) - self.assertRegex(lines[1], self.MSG_REGEX) - self.assertRegex(lines[2], self.MSG_REGEX) + for line in lines: + self.assertRegex(line, self.MSG_REGEX) def test_document_deletion(self): """ @@ -197,14 +196,12 @@ class TestFuzzyMatchCommand(TestCase): stdout, _ = self.call_command("--delete") - lines = [x.strip() for x in stdout.split("\n") if len(x.strip())] - self.assertEqual(len(lines), 3) - self.assertEqual( - lines[0], + self.assertIn( "The command is configured to delete documents. Use with caution", + stdout, ) - self.assertRegex(lines[1], self.MSG_REGEX) - self.assertEqual(lines[2], "Deleting 1 documents based on ratio matches") + self.assertRegex(stdout, self.MSG_REGEX) + self.assertIn("Deleting 1 documents based on ratio matches", stdout) self.assertEqual(Document.objects.count(), 2) self.assertIsNotNone(Document.objects.get(pk=1))