Skip to content
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

Fix republishing of binders with trees latest flag set to null #131

Merged
merged 1 commit into from
Jul 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cnxpublishing/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ def build_tree(nodeid, parent_id):
data = tree[nodeid]
data['parent_id'] = parent_id
if history_map.get(data['ident_hash']) is not None \
and data['latest']:
and (data['latest'] or parent_id is None):
data['ident_hash'] = history_map[data['ident_hash']]
new_nodeid = insert(data)
for child_nodeid in children.get(nodeid, []):
Expand Down
35 changes: 35 additions & 0 deletions cnxpublishing/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,41 @@ def test_republish(self, cursor):
}
self.assertEqual(tree, expected_tree)

@db_connect
def test_republish_binder_tree_not_latest(self, cursor):
"""Verify republishing of binders that has trees with latest flag set
to null in shared document situations. Binders published by
cnx-publishing always have latest flag set to true at the time of
writing. This is for existing binders in the database."""
# * Set up one book in archive. One of the pages in this book will be
# updated causing this book to be republished.
book_one = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor)

# * Set the latest flag in trees for book one to null.
cursor.execute("""\
UPDATE trees SET latest = NULL WHERE documentid = (
SELECT module_ident FROM modules
WHERE uuid||'@'||concat_ws('.', major_version, minor_version) = %s)
""", (book_one.ident_hash,))

# * Make a new publication of page one
page_one = book_one[0][0]
page_one.metadata['version'] = '2'
from ..publish import publish_model
ident_hash = publish_model(cursor, page_one, 'tester', 'test pub')

# * Invoke the republish logic.
self.call_target(cursor, [page_one])

# * Ensure book one has been republished.
cursor.execute("""\
SELECT 1 FROM trees WHERE documentid = (
SELECT module_ident FROM modules
WHERE uuid||'@'||concat_ws('.', major_version, minor_version) =
%s||'@1.2')
""", (book_one.id,))
self.assertEqual((1,), cursor.fetchone())


class PublishCompositeDocumentTestCase(BaseDatabaseIntegrationTestCase):

Expand Down