Package elisa :: Package plugins :: Package good :: Package xmlmenu :: Package tests :: Module test_xml_activity
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.good.xmlmenu.tests.test_xml_activity

  1   
  2  from elisa.core.tests import component_test_case 
  3   
  4  from elisa.plugins.good.xmlmenu.xmltreemenu_activity import XmltreemenuActivity 
  5  from elisa.core.tests.elisa_test_case import BoilerPlateApp, DEFAULT_CONFIG 
  6  from elisa.extern.coherence.et import parse_xml 
  7   
  8  from elisa.core import common 
  9   
 10  import os 
 11   
12 -class TestXmlActvity(component_test_case.ComponentTestCase):
13 14 component_class = XmltreemenuActivity 15
16 - def setUp(self):
25 26 # what if the user HAS a other xml-file? 27
29 plugin_registry = common.application.plugin_registry 30 31 MenuModel = plugin_registry.get_component_class('base:menu_model') 32 ListModel = plugin_registry.get_component_class('base:list_model') 33 34 model = self.component.get_model() 35 36 # check, if we get the correct model 37 self.assertEquals(type(model), MenuModel) 38 39 # check, if the model has the the xml_tag, that is necessary 40 menu_config = self.component._model_configs[model] 41 self.failUnless(menu_config.get('xml_tag')) 42 43 # no known children 44 self.assertEquals(len(model.children), 0) 45 46 # This is a f****** hack, that I don't want to have! 47 def got_first_children(children): 48 self.assertEquals(type(children), ListModel) 49 length = len(children) 50 51 if length <= 0 : 52 self.fail() 53 # Test, if the unload is working 54 self.component.unload(children) 55 self.assertEquals(len(children), 0)
56 57 # get the children 58 children_dfr = self.component.loadmore(model) 59 children_dfr.addCallback(got_first_children) 60 return children_dfr
61
62 - def test_default_xml_translations(self):
63 64 xml_file = os.path.join(self.directory, 65 '..', 66 'data', 67 'default_menu.xml') 68 reader = open(xml_file,'r') 69 70 data = '<Root>' 71 72 for line in reader: 73 line = line.strip() 74 if line.startswith('<Label'): 75 data += '\n%s\t' % line 76 77 data += '\n</Root>' 78 79 xml = parse_xml(data) 80 root = xml.getroot() 81 82 translator = common.application.translator 83 84 strings_by_domain = {} 85 86 for label in root.findall('Label'): 87 string = label.text 88 domain = label.get('translate-domain', None) 89 if domain: 90 if not strings_by_domain.has_key(domain): 91 strings_by_domain[domain] = [] 92 already_found = strings_by_domain[domain] 93 if string not in already_found: 94 already_found.append(string) 95 else: 96 self.fail("'%s' is given without domain!" % string) 97 98 locales = translator._localedirs 99 100 pot_data = {} 101 102 for domain, strings in strings_by_domain.iteritems(): 103 if domain not in locales.keys(): 104 self.fail("Missing domain '%s'" % domain) 105 106 for string in strings: 107 value = False 108 for localedir in locales[domain]: 109 110 if localedir not in pot_data.keys(): 111 112 messages = os.path.join(localedir, 'messages.pot') 113 if not os.path.isfile(messages): 114 #print messages, 'missing. BAD!' 115 continue 116 mes_read = open(messages, 'r') 117 pot_data[localedir] = mes_read.read() 118 mes_read.close() 119 120 data = pot_data[localedir] 121 122 if '\nmsgid "%s"\n' % string in data: 123 value = True 124 break 125 126 if not value: 127 self.fail("'%s' not found in the translation template for" \ 128 " '%s': '%r'" % (string, domain, locales[domain]))
129