-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: don't override next version with new draft #232
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# details. | ||
|
||
"""Data access layer tests.""" | ||
from datetime import timedelta | ||
|
||
import pytest | ||
from invenio_search import current_search_client | ||
|
@@ -133,6 +134,35 @@ def test_draft_parent_state_hard_delete(app, db, location): | |
assert RecordMetadata.query.count() == 0 | ||
|
||
|
||
def test_new_draft_of_published_record_doesnt_override_next_draft_id(app, db, location): | ||
"""Test multiple drafts when editing multiple versions of the same record.""" | ||
# Classic draft of published record having been cleaned up scenario | ||
record_1 = Record.publish(Draft.create({})) | ||
db.session.commit() | ||
Draft.cleanup_drafts(timedelta(0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The most typical case (but relies on cleanup_drafts). |
||
|
||
# Wider test for any situation where draft of record doesn't exist anymore | ||
# e.g. admin force deletion | ||
parent = ParentRecord.create({}) | ||
record_2 = Record.create({}, parent=parent) | ||
record_2.register() | ||
Comment on lines
+146
to
+148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The wider case that covers the above if cleanup_drafts works correctly and covers other scenarios e.g. direct forced deletion etc . In other words, anything that gets us to a published record without a draft. |
||
|
||
db.session.commit() | ||
|
||
for record in [record_1, record_2]: | ||
# Create new_version before a record's draft exists | ||
new_version_draft = Draft.new_version(record) | ||
db.session.commit() | ||
assert record.versions.next_draft_id == new_version_draft.id | ||
assert record.versions.latest_id == record.id | ||
|
||
# Check next_draft_id still holds after edit | ||
Draft.edit(record) | ||
db.session.commit() | ||
assert record.versions.next_draft_id == new_version_draft.id | ||
assert record.versions.latest_id == record.id | ||
|
||
|
||
def test_draft_parent_state_hard_delete_with_parent(app, db, location): | ||
"""Test force deletion of a draft.""" | ||
# Initial state: A previous reccord version exists, in addition to draft | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix. When interacting with the site in the browser it fixes the issue.