示例#1
0
 def test_write_atom_inline(self):
     self.repo.faceted_data = Mock(return_value=self.faceted_data)
     for basefile in range(25):
         de = DocumentEntry(
             self.repo.store.documententry_path(str(basefile)))
         util.writefile(self.repo.store.parsed_path(str(basefile)),
                        "<html><p>Document #%s</p></html>" % basefile)
         de.set_content(self.repo.store.parsed_path(str(basefile)),
                        self.repo.canonical_uri(str(basefile)),
                        inline=True)
         de.save()
     unsorted_entries = self.repo.news_facet_entries()
     entries = sorted(list(unsorted_entries),
                      key=itemgetter('updated'),
                      reverse=True)
     self.repo.news_write_atom(entries,
                               'New and updated documents',
                               'main',
                               archivesize=6)
     tree = etree.parse('%s/base/feed/main.atom' % self.datadir)
     NS = "{http://www.w3.org/2005/Atom}"
     content = tree.find(".//" + NS + "content")
     self.assertIsNotNone(content)
     self.assertIsNone(content.get("src"))
     self.assertIsNone(content.get("hash"))
     self.assertEqual(content.get("type"), "xhtml")
     self.assertEqualXML(
         etree.tostring(content[0]),
         '<html xmlns="http://www.w3.org/2005/Atom" xmlns:le="http://purl.org/atompub/link-extensions/1.0"><p>Document #24</p></html>'
     )
示例#2
0
 def test_write_atom_inline(self):
     self.repo.faceted_data = Mock(return_value=self.faceted_data)
     for basefile in range(25):
         de = DocumentEntry(self.repo.store.documententry_path(str(basefile)))
         util.writefile(self.repo.store.parsed_path(str(basefile)),
                        "<html><p>Document #%s</p></html>" % basefile)
         de.set_content(self.repo.store.parsed_path(str(basefile)),
                        self.repo.canonical_uri(str(basefile)),
                        inline=True)
         de.save()
     unsorted_entries = self.repo.news_facet_entries()
     entries = sorted(list(unsorted_entries),
                      key=itemgetter('updated'), reverse=True)
     self.repo.news_write_atom(entries,
                               'New and updated documents',
                               'main',
                               archivesize=6)
     tree = etree.parse('%s/base/feed/main.atom' % self.datadir)
     NS = "{http://www.w3.org/2005/Atom}"
     content = tree.find(".//"+NS+"content")
     self.assertIsNotNone(content)
     self.assertIsNone(content.get("src"))
     self.assertIsNone(content.get("hash"))
     self.assertEqual(content.get("type"), "xhtml")
     self.assertEqualXML(etree.tostring(content[0]),
                           '<html xmlns="http://www.w3.org/2005/Atom" xmlns:le="http://purl.org/atompub/link-extensions/1.0"><p>Document #24</p></html>')
示例#3
0
    def test_modify(self):
        path = self.repo.store.documententry_path("123/a")
        util.ensure_dir(path)
        with open(path, "w") as fp:
            fp.write(self.basic_json)

        d = DocumentEntry(path=path)
        d.orig_updated = datetime(2013, 3, 27, 20, 59, 42, 325067)
        d.id = "http://example.org/123/a"
        # do this in setUp?
        with open(self.datadir+"/xhtml","w") as f:
            f.write("<div>xhtml fragment</div>")

        d.set_content(self.datadir+"/xhtml", "http://example.org/test",
                      mimetype="xhtml", inline=True)
        d.save()
        self.assertEqual(self.d2u(util.readfile(path)), self.modified_json)
示例#4
0
    def test_modify(self):
        path = self.repo.store.documententry_path("123/a")
        util.ensure_dir(path)
        with open(path, "w") as fp:
            fp.write(self.basic_json)

        d = DocumentEntry(path=path)
        d.orig_updated = datetime(2013, 3, 27, 20, 59, 42, 325067)
        d.id = "http://example.org/123/a"
        # do this in setUp?
        with open(self.datadir+"/xhtml","w") as f:
            f.write("<div>xhtml fragment</div>")

        d.set_content(self.datadir+"/xhtml", "http://example.org/test",
                      mimetype="xhtml", inline=True)
        d.save()
        self.assertEqual(self.d2u(util.readfile(path)), self.modified_json)
示例#5
0
    def test_set_content(self):
        t = tempfile.mktemp()
        with open(t, "w") as f:
            f.write("<div>xhtml fragment</div>")

        d = DocumentEntry()
        d.set_content(t,
                      "http://example.org/test",
                      mimetype="xhtml",
                      inline=True)
        # type must be either "text", "html",  "xhtml" or a MIME media type (RFC 4287, 4.1.3.1)
        self.assertEqual(d.content['type'], "xhtml")
        self.assertEqual(d.content['markup'], "<div>xhtml fragment</div>")
        self.assertIsNone(d.content['src'])

        d = DocumentEntry()
        d.set_content(t, "http://example.org/test", mimetype="xhtml")
        self.assertEqual(d.content['type'], "xhtml")
        self.assertIsNone(d.content['markup'])
        self.assertEqual(d.content['src'], "http://example.org/test")
        self.assertEqual(d.content['hash'],
                         "md5:ca8d87b5cf6edbbe88f51d45926c9a8d")

        os.unlink(t)

        t = tempfile.mktemp()
        with open(t + ".pdf", "w") as f:
            f.write("This is not a real PDF file")

        d = DocumentEntry()
        d.set_content(t + ".pdf", "http://example.org/test")
        self.assertEqual(d.content['type'], "application/pdf")
        self.assertIsNone(d.content['markup'])
        self.assertEqual(d.content['src'], "http://example.org/test")
        self.assertEqual(d.content['hash'],
                         "md5:0a461f0621ede53f1ea8471e34796b6f")

        d = DocumentEntry()
        with self.assertRaises(AssertionError):
            d.set_content(t + ".pdf", "http://example.org/test", inline=True)

        os.unlink(t + ".pdf")
示例#6
0
    def test_set_content(self):
        t = tempfile.mktemp()
        with open(t,"w") as f:
             f.write("<div>xhtml fragment</div>")

        d = DocumentEntry()
        d.set_content(t, "http://example.org/test", mimetype="xhtml", inline=True)
        # type must be either "text", "html",  "xhtml" or a MIME media type (RFC 4287, 4.1.3.1)
        self.assertEqual(d.content['type'],"xhtml")
        self.assertEqual(d.content['markup'],"<div>xhtml fragment</div>")
        self.assertIsNone(d.content['src'])

        d = DocumentEntry()
        d.set_content(t, "http://example.org/test", mimetype="xhtml")
        self.assertEqual(d.content['type'],"xhtml")
        self.assertIsNone(d.content['markup'])
        self.assertEqual(d.content['src'], "http://example.org/test")
        self.assertEqual(d.content['hash'], "md5:ca8d87b5cf6edbbe88f51d45926c9a8d")

        os.unlink(t)
        
        t = tempfile.mktemp()
        with open(t+".pdf","w") as f:
             f.write("This is not a real PDF file")
        
        d = DocumentEntry()
        d.set_content(t+".pdf", "http://example.org/test")
        self.assertEqual(d.content['type'],"application/pdf")
        self.assertIsNone(d.content['markup'])
        self.assertEqual(d.content['src'], "http://example.org/test")
        self.assertEqual(d.content['hash'], "md5:0a461f0621ede53f1ea8471e34796b6f")

        d = DocumentEntry()
        with self.assertRaises(AssertionError):
            d.set_content(t+".pdf", "http://example.org/test", inline=True)

        os.unlink(t+".pdf")