def test(self, cursor): binder = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor) # Build some new metadata for the composite document. metadata = [ x.metadata.copy() for x in cnxepub.flatten_to_documents(binder) ][0] del metadata['cnx-archive-uri'] del metadata['version'] metadata['title'] = "Made up of other things" publisher = [p['id'] for p in metadata['publishers']][0] message = "Composite addition" # Add some fake collation objects to the book. content = '<p class="para">composite</p>' composite_doc = cnxepub.CompositeDocument(None, content, metadata) from cnxpublishing.publish import publish_composite_model ident_hash = publish_composite_model(cursor, composite_doc, binder, publisher, message) # Shim the composite document into the binder. binder.append(composite_doc) tree = cnxepub.model_to_tree(binder) self.target(cursor, tree) cursor.execute("SELECT tree_to_json(%s, %s, TRUE)::json;", ( binder.id, binder.metadata['version'], )) collated_tree = cursor.fetchone()[0] self.assertIn(composite_doc.ident_hash, cnxepub.flatten_tree_to_ident_hashes(collated_tree))
def test(self, cursor): binder = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor) # Build some new metadata for the composite document. metadata = [ x.metadata.copy() for x in cnxepub.flatten_to_documents(binder) ][0] del metadata['cnx-archive-uri'] del metadata['version'] metadata['title'] = "Made up of other things" publisher = [p['id'] for p in metadata['publishers']][0] message = "Composite addition" # Add some fake collation objects to the book. content = '<p class="para">composite</p>' composite_doc = cnxepub.CompositeDocument(None, content, metadata) ident_hash = self.target(cursor, composite_doc, binder, publisher, message) # Ensure the model's identifiers has been set. self.assertEqual(ident_hash, composite_doc.ident_hash) self.assertEqual(ident_hash, composite_doc.get_uri('cnx-archive')) # The only thing different in the module metadata insertion is # the `portal_type` value cursor.execute( "SELECT portal_type " "FROM modules " "WHERE ident_hash(uuid, major_version, minor_version) = %s", (ident_hash, )) portal_type = cursor.fetchone()[0] self.assertEqual(portal_type, 'CompositeModule') # Ensure the file entry and association entry. cursor.execute( """\ SELECT f.file FROM collated_file_associations AS cfa NATURAL JOIN files AS f, modules AS m1, -- context modules AS m2 -- item WHERE (ident_hash(m1.uuid, m1.major_version, m1.minor_version) = %s AND m1.module_ident = cfa.context) AND (ident_hash(m2.uuid, m2.major_version, m2.minor_version) = %s AND m2.module_ident = cfa.item)""", ( binder.ident_hash, ident_hash, )) persisted_content = cursor.fetchone()[0][:] self.assertIn(content, persisted_content)
def setUp(self, cursor): super(RemoveBakedTestCase, self).setUp() binder = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor) cursor.connection.commit() publisher = 'ream' msg = 'part of collated publish' # Build some new metadata for the composite document. metadata = [ x.metadata.copy() for x in cnxepub.flatten_to_documents(binder) ][0] del metadata['cnx-archive-uri'] del metadata['version'] metadata['created'] = None metadata['revised'] = None metadata['title'] = "Made up of other things" # Add some fake collation objects to the book. content = '<p>composite</p>' composite_doc = cnxepub.CompositeDocument(None, content, metadata) composite_section = cnxepub.TranslucentBinder( nodes=[composite_doc], metadata={'title': "Other things"}) baked_doc_content = '<p>collated</p>' def cnxepub_collate(binder_model, ruleset=None, includes=None): binder_model[0][0].content = baked_doc_content binder_model.append(composite_section) return binder_model with mock.patch('cnxpublishing.bake.collate_models') as mock_collate: mock_collate.side_effect = cnxepub_collate from cnxpublishing.bake import bake fake_recipe_id = 1 errors = bake(binder, fake_recipe_id, publisher, msg, cursor=cursor) self.ident_hash = binder.ident_hash self.composite_ident_hash = composite_doc.ident_hash self.baked_doc_sha1 = self._get_file_sha1(cursor, binder[0][0], binder) self.composite_doc_sha1 = self._get_file_sha1(cursor, composite_doc, binder)
def test(self, cursor): binder = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor) cursor.connection.commit() publisher = 'ream' msg = 'part of collated publish' # Build some new metadata for the composite document. metadata = [ x.metadata.copy() for x in cnxepub.flatten_to_documents(binder) ][0] del metadata['cnx-archive-uri'] del metadata['version'] metadata['created'] = None metadata['revised'] = None metadata['title'] = "Made up of other things" # Add some fake collation objects to the book. content = '<p>composite</p>' composite_doc = cnxepub.CompositeDocument(None, content, metadata) composite_section = cnxepub.TranslucentBinder( nodes=[composite_doc], metadata={'title': "Other things"}) baked_doc_content = '<p>collated</p>' def cnxepub_collate(binder_model, ruleset=None, includes=None): binder_model[0][0].content = baked_doc_content binder_model.append(composite_section) return binder_model fake_recipe_id = 1 with mock.patch('cnxpublishing.bake.collate_models') as mock_collate: mock_collate.side_effect = cnxepub_collate errors = self.target(binder, fake_recipe_id, publisher, msg) # Ensure the output of the errors. self.assertEqual(errors, []) # Ensure the original tree is intact. cursor.execute("SELECT tree_to_json(%s, %s, FALSE)::json;", ( binder.id, binder.metadata['version'], )) tree = cursor.fetchone()[0] self.assertNotIn(composite_doc.ident_hash, cnxepub.flatten_tree_to_ident_hashes(tree)) # Ensure the tree as been stamped. cursor.execute("SELECT tree_to_json(%s, %s, TRUE)::json;", ( binder.id, binder.metadata['version'], )) baked_tree = cursor.fetchone()[0] self.assertIn(composite_doc.ident_hash, cnxepub.flatten_tree_to_ident_hashes(baked_tree)) # Ensure the changes to a document content were persisted. content_to_check = [ ( binder[0][0], baked_doc_content, ), ( composite_doc, content, ), ] for doc, content in content_to_check: self.assertIn(content, self._get_baked_file(cursor, doc, binder))