Ejemplo n.º 1
0
 cnxepub.TranslucentBinder(
     metadata={u'title': u'Part One'},
     nodes=[
         cnxepub.TranslucentBinder(
             metadata={u'title': u'Chapter One'},
             title_overrides=['Document One'],
             nodes=[
                 cnxepub.Document(
                     id=u'2cf4d7d3@draft',
                     data=
                     u'<p class="para">If you finish the book, there will be cake.</p><img src="../resources/{}">'
                     .format(RESOURCE_ONE_FILENAME),
                     resources=[
                         cnxepub.Resource(
                             RESOURCE_ONE_FILENAME,
                             _read_file(RESOURCE_ONE_FILEPATH, 'rb'),
                             'image/png',
                             filename=RESOURCE_ONE_FILENAME)
                     ],
                     metadata={
                         u'title':
                         u'Document One of Infinity',
                         u'created':
                         u'2013/03/19 15:01:16 -0500',
                         u'revised':
                         u'2013/03/19 15:01:16 -0500',
                         u'keywords': [u'South Africa'],
                         u'subjects': [
                             u'Mathematics and Statistics',
                         ],
                         u'summary':
Ejemplo n.º 2
0
 def make_resource(self, id, data, media_type):
     resource = cnxepub.Resource(id, data, media_type)
     return resource
Ejemplo n.º 3
0
    def test_revised_module_inserted(self, cursor):
        self.target()

        binder = use_cases.setup_COMPLEX_BOOK_ONE_in_archive(self, cursor)
        cursor.connection.commit()

        revised = deepcopy(use_cases.COMPLEX_BOOK_ONE)
        revised.id = binder.id
        revised.metadata['cnx-archive-uri'] = binder.id
        revised.metadata['version'] = '2.1'
        revised[0][0] = binder[0][0]
        revised[0][1] = binder[0][1]
        revised[1][0] = binder[1][0]
        revised[1][1] = binder[1][1]

        revised.resources.append(
            cnxepub.Resource('ruleset.css',
                             io.BytesIO("""\
p.para {
  content: "Ruleset applied";
}

/* copied from cnx-recipes books/rulesets/output/physics.css */
body > div[data-type="page"]:pass(20)::after,
body > div[data-type="composite-page"]:pass(20)::after {
  content: pending(page-link);
  move-to: eob-toc;
  container: li;
}
body > div[data-type='chapter'] > h1[data-type='document-title']:pass(20) {
  copy-to: eoc-toc;
}
body > div[data-type='chapter'] > div[data-type="page"]:pass(20),
body > div[data-type='chapter'] > div[data-type="composite-page"]:pass(20) {
  string-set: page-idi attr(id);
}
body > div[data-type='chapter'] > div[data-type="page"] > [data-type='document-title']:pass(20),
body > div[data-type='chapter'] > div[data-type="composite-page"] > [data-type='document-title']:pass(20) {
  copy-to: page-title;
}
body > div[data-type='chapter'] > div[data-type="page"]:pass(20)::after,
body > div[data-type='chapter'] > div[data-type="composite-page"]:pass(20)::after {
  content: pending(page-title);
  attr-href: "#" string(page-id);
  container: a;
  move-to: page-link;
}
body > div[data-type='chapter'] > div[data-type="page"]:pass(20)::after,
body > div[data-type='chapter'] > div[data-type="composite-page"]:pass(20)::after {
  content: pending(page-link);
  move-to: eoc-toc-pages;
  container: li;
}
body > div[data-type='chapter']:pass(20)::after {
  content: pending(eoc-toc-pages);
  container: ol;
  class: chapter;
  move-to: eoc-toc;
}
body > div[data-type='chapter']:pass(20)::after {
  content: pending(eoc-toc);
  container: li;
  move-to: eob-toc;
}
body > div[data-type="unit"] > h1[data-type='document-title']:pass(20) {
  copy-to: eou-toc;
}
body > div[data-type="unit"] > div[data-type='chapter'] > h1[data-type='document-title']:pass(20) {
  copy-to: eoc-toc;
}
body > div[data-type="unit"] > div[data-type='chapter'] > div[data-type="page"] > [data-type='document-title']:pass(20),
body > div[data-type="unit"] > div[data-type='chapter'] div[data-type="composite-page"] > [data-type='document-title']:pass(20) {
  copy-to: page-title;
}
body > div[data-type="unit"] > div[data-type='chapter'] > div[data-type="page"]:pass(20)::after,
body > div[data-type="unit"] > div[data-type='chapter'] div[data-type="composite-page"]:pass(20)::after {
  content: pending(page-title);
  move-to: eoc-toc-pages;
  container: li;
}
body > div[data-type="unit"] > div[data-type='chapter']:pass(20)::after {
  content: pending(eoc-toc-pages);
  container: ol;
  class: chapter;
  move-to: eoc-toc;
}
body > div[data-type="unit"] > div[data-type='chapter']:pass(20)::after {
  content: pending(eoc-toc);
  container: li;
  move-to: eou-toc-chapters;
}
body > div[data-type="unit"]:pass(20)::after {
  content: pending(eou-toc-chapters);
  container: ol;
  class: unit;
  move-to: eou-toc;
}
body > div[data-type="unit"]:pass(20)::after {
  content: pending(eou-toc);
  container: li;
  move-to: eob-toc;
}
nav#toc:pass(30) {
  content: '';
}
nav#toc:pass(30)::after {
  content: pending(eob-toc);
  container: ol;
}
"""),
                             'text/css',
                             filename='ruleset.css'))

        from ...publish import publish_model
        publisher = 'karenc'
        publication_message = 'Added a ruleset'
        publish_model(cursor, revised, publisher, publication_message)
        cursor.connection.commit()

        cursor.execute("""\
SELECT module_ident FROM modules
    WHERE portal_type = 'Collection'
    ORDER BY module_ident DESC LIMIT 1""")
        module_ident = cursor.fetchone()[0]

        wait_for_module_state(module_ident)

        cursor.execute(
            """\
SELECT nodeid, is_collated FROM trees WHERE documentid = %s
    ORDER BY nodeid""", (module_ident, ))
        is_collated = [i[1] for i in cursor.fetchall()]
        self.assertEqual([False, True], is_collated)

        content = get_collated_content(revised[0][0].ident_hash,
                                       revised.ident_hash, cursor)
        self.assertIn('Ruleset applied', content[:])

        cursor.execute(
            """\
SELECT state FROM post_publications
    WHERE module_ident = %s ORDER BY timestamp DESC""", (module_ident, ))
        self.assertEqual('Done/Success', cursor.fetchone()[0])