Example #1
0
    def generate_response(self, results, queries, osHostURL, context):
        ospath = generate_autodiscovery_path(osHostURL, None, self.extension, rel = None)
        
        #Generates the ATOM document
        atomdoc = createAtomDocument(ospath + "atom", results.title, results.updated)

        #Generate feed's links
        self._generate_feed_links(atomdoc, ospath, results)
        
        #Inserts the OpenSearchResponse elements
        createOpenSearchRespose(atomdoc, results.totalResult, results.startIndex, results.count, queries)
        
        self.generateEntries(atomdoc, results.subresult, ospath)
        
        reparsed = minidom.parseString(tostring(atomdoc))
        return reparsed.toprettyxml(indent="  ")
Example #2
0
    def entry_test(self):
        atom = createAtom()
        title = createTitle(root=atom, body="testEntry")
        iid = createID(1, root=atom)
        update = createUpdated("2012-0619T21:02:00.626Z", root=atom)
        entry = createEntry(iid, title, update, root=atom)
        atom.append(entry)
        self.assertEqual(
            tostring(atom),
            '<feed xmlns="http://www.w3.org/2005/Atom">\
<entry><id>1</id><title>testEntry</title><updated>2012-0619T21:02:00.626Z</updated></entry></feed>',
        )

        root = Element("myCustomTag")
        title = createTitle(root=root, body="testEntry")
        iid = createID(1, root=root)
        update = createUpdated("2012-0619T21:02:00.626Z", root=atom)
        atom = createEntry(iid, title, update, root=root)
        root.append(atom)
        self.assertEqual(
            tostring(root),
            '<myCustomTag xmlns:atom="http://www.w3.org/2005/Atom">\
<atom:entry><atom:id>1</atom:id><atom:title>testEntry</atom:title><updated>2012-0619T21:02:00.626Z</updated>\
</atom:entry></myCustomTag>',
        )

        root = createAtomDocument(1, "atomTitle", "2012-0619T21:02:00.626Z")
        iid = createID(2, root=root)
        title = createTitle(root=root, body="testEntry")
        update = createUpdated("2012-0619T21:02:00.626Z", root=root)
        entry = createEntry(iid, title, update, root=root)
        root.append(entry)
        self.assertEqual(
            tostring(root),
            '<feed xmlns="http://www.w3.org/2005/Atom"><id>1</id>\
<title>atomTitle</title><updated>2012-0619T21:02:00.626Z</updated><entry><id>2</id>\
<title>testEntry</title><updated>2012-0619T21:02:00.626Z</updated></entry></feed>',
            "Error",
        )