Update document modified on add or delete notes
d
This commit is contained in:
parent
01af725d79
commit
7984ad89ed
@ -2354,13 +2354,18 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
WHEN:
|
WHEN:
|
||||||
- API request is made to add a note
|
- API request is made to add a note
|
||||||
THEN:
|
THEN:
|
||||||
- note is created and associated with document
|
- note is created and associated with document, modified time is updated
|
||||||
"""
|
"""
|
||||||
doc = Document.objects.create(
|
doc = Document.objects.create(
|
||||||
title="test",
|
title="test",
|
||||||
mime_type="application/pdf",
|
mime_type="application/pdf",
|
||||||
content="this is a document which will have notes added",
|
content="this is a document which will have notes added",
|
||||||
|
created=timezone.now() - timedelta(days=1),
|
||||||
)
|
)
|
||||||
|
# set to yesterday
|
||||||
|
doc.modified = timezone.now() - timedelta(days=1)
|
||||||
|
self.assertEqual(doc.modified.day, (timezone.now() - timedelta(days=1)).day)
|
||||||
|
|
||||||
resp = self.client.post(
|
resp = self.client.post(
|
||||||
f"/api/documents/{doc.pk}/notes/",
|
f"/api/documents/{doc.pk}/notes/",
|
||||||
data={"note": "this is a posted note"},
|
data={"note": "this is a posted note"},
|
||||||
@ -2382,6 +2387,10 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(resp_data["note"], "this is a posted note")
|
self.assertEqual(resp_data["note"], "this is a posted note")
|
||||||
|
|
||||||
|
doc = Document.objects.get(pk=doc.pk)
|
||||||
|
# modified was updated to today
|
||||||
|
self.assertEqual(doc.modified.day, timezone.now().day)
|
||||||
|
|
||||||
def test_notes_permissions_aware(self):
|
def test_notes_permissions_aware(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
@ -2441,17 +2450,21 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
def test_delete_note(self):
|
def test_delete_note(self):
|
||||||
"""
|
"""
|
||||||
GIVEN:
|
GIVEN:
|
||||||
- Existing document
|
- Existing document, existing note
|
||||||
WHEN:
|
WHEN:
|
||||||
- API request is made to add a note
|
- API request is made to delete a note
|
||||||
THEN:
|
THEN:
|
||||||
- note is created and associated with document
|
- note is deleted, document modified is updated
|
||||||
"""
|
"""
|
||||||
doc = Document.objects.create(
|
doc = Document.objects.create(
|
||||||
title="test",
|
title="test",
|
||||||
mime_type="application/pdf",
|
mime_type="application/pdf",
|
||||||
content="this is a document which will have notes!",
|
content="this is a document which will have notes!",
|
||||||
|
created=timezone.now() - timedelta(days=1),
|
||||||
)
|
)
|
||||||
|
# set to yesterday
|
||||||
|
doc.modified = timezone.now() - timedelta(days=1)
|
||||||
|
self.assertEqual(doc.modified.day, (timezone.now() - timedelta(days=1)).day)
|
||||||
note = Note.objects.create(
|
note = Note.objects.create(
|
||||||
note="This is a note.",
|
note="This is a note.",
|
||||||
document=doc,
|
document=doc,
|
||||||
@ -2466,6 +2479,9 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase):
|
|||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
|
||||||
self.assertEqual(len(Note.objects.all()), 0)
|
self.assertEqual(len(Note.objects.all()), 0)
|
||||||
|
doc = Document.objects.get(pk=doc.pk)
|
||||||
|
# modified was updated to today
|
||||||
|
self.assertEqual(doc.modified.day, timezone.now().day)
|
||||||
|
|
||||||
def test_get_notes_no_doc(self):
|
def test_get_notes_no_doc(self):
|
||||||
"""
|
"""
|
||||||
|
@ -522,6 +522,9 @@ class DocumentViewSet(
|
|||||||
)
|
)
|
||||||
c.save()
|
c.save()
|
||||||
|
|
||||||
|
doc.modified = timezone.now()
|
||||||
|
doc.save()
|
||||||
|
|
||||||
from documents import index
|
from documents import index
|
||||||
|
|
||||||
index.add_or_update_document(self.get_object())
|
index.add_or_update_document(self.get_object())
|
||||||
@ -545,6 +548,9 @@ class DocumentViewSet(
|
|||||||
note = Note.objects.get(id=int(request.GET.get("id")))
|
note = Note.objects.get(id=int(request.GET.get("id")))
|
||||||
note.delete()
|
note.delete()
|
||||||
|
|
||||||
|
doc.modified = timezone.now()
|
||||||
|
doc.save()
|
||||||
|
|
||||||
from documents import index
|
from documents import index
|
||||||
|
|
||||||
index.add_or_update_document(self.get_object())
|
index.add_or_update_document(self.get_object())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user