mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-15 12:29:29 -05:00
Coverage
This commit is contained in:
parent
8d7e179a6d
commit
360b11ae26
@ -171,6 +171,32 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
results = response.data["results"]
|
results = response.data["results"]
|
||||||
self.assertEqual(len(results[0]), 0)
|
self.assertEqual(len(results[0]), 0)
|
||||||
|
|
||||||
|
def test_document_update_with_created_date(self):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- Existing document
|
||||||
|
WHEN:
|
||||||
|
- Document is updated with created_date and not created
|
||||||
|
THEN:
|
||||||
|
- Document created field is updated
|
||||||
|
"""
|
||||||
|
doc = Document.objects.create(
|
||||||
|
title="none",
|
||||||
|
checksum="123",
|
||||||
|
mime_type="application/pdf",
|
||||||
|
created=date(2023, 1, 1),
|
||||||
|
)
|
||||||
|
|
||||||
|
created_date = date(2023, 2, 1)
|
||||||
|
self.client.patch(
|
||||||
|
f"/api/documents/{doc.pk}/",
|
||||||
|
{"created_date": created_date},
|
||||||
|
format="json",
|
||||||
|
)
|
||||||
|
|
||||||
|
doc.refresh_from_db()
|
||||||
|
self.assertEqual(doc.created_date, created_date)
|
||||||
|
|
||||||
def test_document_actions(self):
|
def test_document_actions(self):
|
||||||
_, filename = tempfile.mkstemp(dir=self.dirs.originals_dir)
|
_, filename = tempfile.mkstemp(dir=self.dirs.originals_dir)
|
||||||
|
|
||||||
|
36
src/documents/tests/test_migration_created.py
Normal file
36
src/documents/tests/test_migration_created.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from documents.tests.utils import DirectoriesMixin
|
||||||
|
from documents.tests.utils import TestMigrations
|
||||||
|
|
||||||
|
|
||||||
|
class TestMigrateDocumentCreated(DirectoriesMixin, TestMigrations):
|
||||||
|
migrate_from = "1065_workflowaction_assign_custom_fields_values"
|
||||||
|
migrate_to = "1066_alter_document_created"
|
||||||
|
|
||||||
|
def setUpBeforeMigration(self, apps):
|
||||||
|
# create 600 documents
|
||||||
|
for i in range(600):
|
||||||
|
Document = apps.get_model("documents", "Document")
|
||||||
|
Document.objects.create(
|
||||||
|
title=f"test{i}",
|
||||||
|
mime_type="application/pdf",
|
||||||
|
filename=f"file{i}.pdf",
|
||||||
|
created=datetime(
|
||||||
|
2023,
|
||||||
|
10,
|
||||||
|
1,
|
||||||
|
12,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
+ timedelta(days=i),
|
||||||
|
checksum=i,
|
||||||
|
)
|
||||||
|
|
||||||
|
def testDocumentCreatedMigrated(self):
|
||||||
|
Document = self.apps.get_model("documents", "Document")
|
||||||
|
|
||||||
|
doc = Document.objects.get(id=1)
|
||||||
|
self.assertEqual(doc.created, datetime(2023, 10, 1, 12, 0, 0).date())
|
Loading…
x
Reference in New Issue
Block a user