Enhancement: log when pre-check fails for documents in trash (#7355)

This commit is contained in:
shamoon
2024-08-05 17:01:01 -07:00
committed by GitHub
parent 839fb34c8e
commit 0ee85aae21
4 changed files with 105 additions and 20 deletions

View File

@@ -322,6 +322,18 @@ class TestConsumer(
shutil.copy(src, dst)
return dst
def get_test_file2(self):
src = (
Path(__file__).parent
/ "samples"
/ "documents"
/ "originals"
/ "0000002.pdf"
)
dst = self.dirs.scratch_dir / "sample2.pdf"
shutil.copy(src, dst)
return dst
def get_test_archive_file(self):
src = (
Path(__file__).parent / "samples" / "documents" / "archive" / "0000001.pdf"
@@ -642,6 +654,47 @@ class TestConsumer(
with self.get_consumer(self.get_test_file()) as consumer:
consumer.run()
def testDuplicateInTrash(self):
with self.get_consumer(self.get_test_file()) as consumer:
consumer.run()
Document.objects.all().delete()
with self.get_consumer(self.get_test_file()) as consumer:
with self.assertRaisesMessage(ConsumerError, "document is in the trash"):
consumer.run()
def testAsnExists(self):
with self.get_consumer(
self.get_test_file(),
DocumentMetadataOverrides(asn=123),
) as consumer:
consumer.run()
with self.get_consumer(
self.get_test_file2(),
DocumentMetadataOverrides(asn=123),
) as consumer:
with self.assertRaisesMessage(ConsumerError, "ASN 123 already exists"):
consumer.run()
def testAsnExistsInTrash(self):
with self.get_consumer(
self.get_test_file(),
DocumentMetadataOverrides(asn=123),
) as consumer:
consumer.run()
document = Document.objects.first()
document.delete()
with self.get_consumer(
self.get_test_file2(),
DocumentMetadataOverrides(asn=123),
) as consumer:
with self.assertRaisesMessage(ConsumerError, "document is in the trash"):
consumer.run()
@mock.patch("documents.parsers.document_consumer_declaration.send")
def testNoParsers(self, m):
m.return_value = []