Attachment 'test_text_x_hcard.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3     MoinMoin unittests of hCard parser
   4 """
   5 from MoinMoin.request import request_cli
   6 from MoinMoin.Page import Page
   7 from MoinMoin.formatter.text_plain import Formatter
   8 from MoinMoin.parser.text_x_hcard import Parser
   9 
  10 PAGENAME = u'ThisPageDoesNotExistAndWillNeverBeReally'
  11 class ParserTestCase(object):
  12     def parse(self, body):
  13         request = self.request
  14         assert body is not None
  15         request.reset()
  16         page = Page(request, PAGENAME)
  17         page.hilite_re = None
  18         page.set_raw_body(body)
  19         formatter = Formatter(request)
  20         formatter.setPage(page)
  21         page.formatter = formatter
  22         request.formatter = formatter
  23         parser = Parser(body, request)
  24         formatter.startContent('')
  25         output = request.redirectedOutput(parser.format, formatter)
  26         formatter.endContent()
  27         return output
  28 
  29 class TestHCard(ParserTestCase):
  30     def test_simple_hcard(self):
  31         src = '''<div id="hcard-Me-Moi" class="vcard">
  32 <span class="fn">Me Moi</span></div>'''
  33         result = self.parse(src)
  34         assert result == u'KeyTypeValue*Name*//Me Moi'
  35 
  36     def test_address(self):
  37         src = '''<div id="hcard-Me-Moi" class="vcard">
  38  <span class="fn">Me Moi</span>
  39  <div class="adr">
  40   <div class="street-address">Big Street 10</div>
  41   <span class="locality">Town</span>, 
  42   <span class="postal-code">12345</span>
  43   <span class="country-name">Germany</span>
  44  </div></div>'''
  45         result = self.parse(src)
  46         assert result == u'KeyTypeValue*Name*//Me Moi*Street Address*//Big Street 10*Locality*//Town*Postal Code*//12345*Country*//Germany'
  47 
  48     def test_nice_value(self):
  49         # TODO: the same with not nice value
  50         src = '''<div id="hcard-Me-Moi" class="vcard">
  51 <a class="url fn" href="http://example.org/">Me Moi</a>
  52 </div>'''
  53         result = self.parse(src)
  54         assert result == u'KeyTypeValue*Name*//Me Moi*Homepage*//http://example.org/ [None]'
  55 
  56     def test_with_image(self):
  57         src = '''<div id="hcard-Me-Moi" class="vcard">
  58   <img style="float:left; margin-right:4px"
  59   src="http://static.wikiwikiweb.de/logos/moinmoin.png" alt="photo"
  60   class="photo"/>
  61  <span class="fn">Me Moi</span>
  62 </div>'''
  63         result = self.parse(src)
  64         assert result == u'KeyTypeValue*Name*//Me Moi*Photo*// [None]'
  65 
  66     def test_with_logo(self):
  67         src = '''<div id="hcard-Me-Moi" class="vcard">
  68   <img style="float:left; margin-right:4px"
  69   src="http://static.wikiwikiweb.de/logos/moinmoin.png" alt="logo" class="logo"/>
  70  <span class="fn">Me Moi</span>
  71 </div>'''
  72         result = self.parse(src)
  73         assert result == u'KeyTypeValue*Name*//Me Moi*Logo*// [None]'
  74 
  75     def test_with_all(self):
  76         src = '''<div id="hcard-Me-Ich-Moi" class="vcard">
  77   <img style="float:left; margin-right:4px" src="http://static.wikiwikiweb.de/logos/moinmoin.png" alt="photo" class="photo"/>
  78  <a class="url fn n" href="http://example.org">  <span class="given-name">Me</span>
  79   <span class="additional-name">Ich</span>
  80   <span class="family-name">Moi</span>
  81 </a>
  82  <div class="org">My Organisation</div>
  83  <a class="email" href="mailto:you@example.org">you@example.org</a>
  84  <div class="adr">
  85   <div class="street-address">Big Street 10</div>
  86   <span class="locality">Town</span>
  87 , 
  88   <span class="region">Far Away</span>
  89 , 
  90   <span class="postal-code">12345</span>
  91 
  92   <span class="country-name">cockaigne</span>
  93 
  94  </div>
  95  <div class="tel">123456789</div>
  96 <div class="tags"><a href="http://kitchen.technorati.com/contacts/tag/me">me</a> <a href="http://kitchen.technorati.com/contacts/tag/myself">myself</a> <a href="http://kitchen.technorati.com/contacts/tag/I">I</a> </div><p style="font-size:smaller;">This <a href="http://microformats.org/wiki/hcard">hCard</a> created with the <a href="http://microformats.org/code/hcard/creator">hCard creator</a>.</p>
  97 </div>'''
  98         result = self.parse(src)
  99         # TODO: strange homepage + email, telephone, street-address missing -> FAILS
 100         # result contains u'KeyTypeValue*Photo*// [None]*Organisation*//My
 101         # Organisation*Homepage*//http:...t 10*Locality*//Town*Region*//Far
 102         # Away*Postal Code*//12345*Country*//Cockaigne'
 103         assert result == u'KeyTypeValue*Photo*// [None]*Organisation*//My Organisation*Homepage*//http:example.org/*Email*//you@example.org*Telephone*//123456879*Street Address*//Big Street 10//*Locality*//Town*Region*//Far Away*Postal Code*//12345*Country*//Cockaigne'
 104 
 105 if __name__ == '__main__':
 106     TestHCard().test()

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-02-10 21:25:23, 169.7 KB) [[attachment:fullpatch.diff]]
  • [get | view] (2008-02-10 21:24:58, 4.4 KB) [[attachment:test_text_x_hcard.py]]
  • [get | view] (2008-02-10 21:25:03, 1.7 KB) [[attachment:text_vcard.py]]
  • [get | view] (2008-02-10 21:25:09, 7.7 KB) [[attachment:text_x_hcard.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.