@@ -213,3 +213,67 @@ def __init__(self):
213213 l .build_tree ()
214214
215215 self .assertEqual (self .xml , str (l ))
216+
217+
218+ class Namespaces (unittest .TestCase ):
219+ def setUp (self ):
220+ self .xml = "<?xml version='1.0' encoding='UTF-8'?>\n "
221+ self .xml += "<rss "
222+ self .xml += "xmlns:opensearch=\" http://a9.com/-/spec/opensearch/1.1/\" "
223+ self .xml += "xmlns:atom=\" http://www.w3.org/2005/Atom\" "
224+ self .xml += "version=\" 2.0\" >"
225+ self .xml += "<channel><link>http://example.com/New+York+history</link>"
226+ self .xml += "<atom:link "
227+ self .xml += "href=\" http://example.com/opensearchdescription.xml\" "
228+ self .xml += "rel=\" search\" "
229+ self .xml += "type=\" application/opensearchdescription+xml\" />"
230+ self .xml += "<opensearch:totalResults>4230000</opensearch:totalResults>"
231+ self .xml += "</channel>"
232+ self .xml += "</rss>"
233+
234+ def test_namesapces_root (self ):
235+
236+
237+ NAMESPACES = {
238+ 'opensearch' : 'http://a9.com/-/spec/opensearch/1.1/' ,
239+ 'atom' : 'http://www.w3.org/2005/Atom'
240+ }
241+
242+ class Channel (XmlModel ):
243+
244+ _sort_order = ('link' , 'atom_link' , 'os_total_results' )
245+
246+ def __init__ (self ):
247+ self .channel = XmlField ('channel' )
248+ self .link = XmlField ('link' )
249+ self .atom_link = XmlField (
250+ 'link' , namespace = NAMESPACES ['atom' ]
251+ )
252+ self .os_total_results = XmlField (
253+ 'totalResults' , namespace = NAMESPACES ['opensearch' ]
254+ )
255+ super (Channel , self ).__init__ ('Channel' , 'channel' , drop_empty = False )
256+
257+ class Rss (XmlModel ):
258+
259+ _sort_order = ('channel' , )
260+
261+ def __init__ (self ):
262+ self .tag = XmlField ('rss' , attributes = {
263+ 'version' : '2.0' , 'nsmap' : NAMESPACES
264+ })
265+ self .channel = Channel ()
266+ super (Rss , self ).__init__ ('RSS' , 'tag' , drop_empty = False )
267+
268+ rss = Rss ()
269+ rss .channel .atom_link .attributes .update ({
270+ 'rel' : 'search' ,
271+ 'type' : 'application/opensearchdescription+xml' ,
272+ 'href' : 'http://example.com/opensearchdescription.xml'
273+ })
274+ rss .channel .feed ({
275+ 'link' : 'http://example.com/New+York+history' ,
276+ 'os_total_results' : 4230000 ,
277+ })
278+ rss .build_tree ()
279+ self .assertEqual (self .xml , str (rss ))
0 commit comments