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

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

  1   
  2  from elisa.core.bus import bus_message 
  3  from elisa.core import common 
  4   
  5  from elisa.extern.coherence.et import parse_xml 
  6   
  7  from node_builder_test import NodeBuilderTest, StupidModel 
  8  from elisa.core.tests.elisa_test_case import ElisaTestCase, BoilerPlateApp, DEFAULT_CONFIG 
  9   
10 -class LocationsBuilderTest(NodeBuilderTest, ElisaTestCase):
11 component_path = 'xmlmenu:locations_builder' 12 entry_identifiers = ['locations'] 13
15 self.component.config = {'auto_locations' : 1, 16 'locations' : [ 'file:///tmp/music', 17 'file:///tmp/media', 18 'file:///tmp/video', 19 'file:///tmp/fotos', 20 'scheme://host/path', 21 'bad_uri?haha&he&', ## This one should fail 22 ], 23 'file:///tmp/music' : {'only_media' : ['audio'], 24 'location_type' : 'other', 25 }, 26 'file:///tmp/video' : {'only_media' : ['video'], 27 'label' : 'yehaa' 28 }, 29 'file:///tmp/media' : {'only_media' : ['audio', 'video'] 30 } 31 } 32 self.component._locations = [] 33 self.component.initialize() 34 locations = self.component._locations 35 36 location_uris = [u'file:///tmp/music', u'file:///tmp/media', 37 u'file:///tmp/video', u'file:///tmp/fotos', 38 u'scheme://host/path'] 39 40 location_by_uri = {} 41 42 for location in locations: 43 uri = unicode(location.uri) 44 location_by_uri[uri] = location 45 if uri in location_uris: 46 location_uris.remove(uri) 47 48 # lets see, if we found all, even with the wrong scheme 49 self.assertEquals(location_uris, []) 50 51 # lets check, that he filtered the bad uri without failing 52 bad_uri = [u'bad_uri?hah&he&'] 53 for uri in bad_uri: 54 if uri in location_by_uri.keys(): 55 self.fail(uri) 56 57 # lets check the attributes are set correctly 58 location = location_by_uri[u'file:///tmp/music'] 59 self.assertEquals(location.media_types, ['audio']) 60 self.assertEquals(location.location_type, 'other') 61 62 location = location_by_uri[u'file:///tmp/media'] 63 self.assertEquals(location.media_types,['audio','video']) 64 self.assertEquals(location.location_type, 'local') 65 66 location = location_by_uri[u'file:///tmp/video'] 67 self.assertEquals(location.media_types, ['video']) 68 self.assertEquals(location.location_type, 'local') 69 self.assertEquals(location.uri.label, 'yehaa') 70 71 data = """ 72 <MenuEntry type='locations'> 73 </MenuEntry> 74 """ 75 root = parse_xml(data).getroot() 76 77 def done_callback(data,test_model): 78 # it has to contain at least our 5 Items! 79 self.failIf(len(test_model.children) < 5)
80 81 test_model = StupidModel() 82 menu_config = { 83 'DefaultDirsIcon' : 'dir_icon', 84 'DefaultFilesIcon' : 'file_icon', 85 'MediaFilter' : 'ANY', 86 'ContentType' : 'sections' } 87 self.xmlmenu._model_configs[test_model] = menu_config 88 dfr = self.component.build_menu_entry(test_model, root) 89 dfr.addCallback(done_callback, test_model) 90 return dfr
91
92 - def test_parent_node_appear(self):
93 data = """ 94 <MenuEntry type='locations'> 95 <ParentNode> 96 <Label translate-domain='elisa-base'>Folders</Label> 97 <Icon>audio_by_folder_icon</Icon> 98 </ParentNode> 99 </MenuEntry> 100 """ 101 root = parse_xml(data).getroot() 102 103 def done_callback(data,test_model): 104 # it has to contain at least our 5 Items! 105 self.failIf(len(test_model.children) < 5)
106 107 test_model = StupidModel() 108 test_model.activity = self.xmlmenu 109 menu_config = { 110 'DefaultDirsIcon' : 'dir_icon', 111 'DefaultFilesIcon' : 'file_icon', 112 'MediaFilter' : 'ANY', 113 'ContentType' : 'sections' } 114 self.xmlmenu._model_configs[test_model] = menu_config 115 dfr = self.component.build_menu_entry(test_model, root) 116 dfr.addCallback(done_callback, test_model) 117 return dfr 118
119 - def test_parent_node_not_appear(self):
120 data = """ 121 <MenuEntry type='locations'> 122 <ParentNode> 123 <Label>test_folder</Label> 124 <Icon>audio_by_folder_icon</Icon> 125 </ParentNode> 126 <Filter type='uri_scheme'>foo:bar</Filter> 127 </MenuEntry> 128 """ 129 root = parse_xml(data).getroot() 130 131 def done_callback(data,test_model): 132 # it has to contain at least our 5 Items! 133 for item in test_model.children: 134 # fail, if the test_folder is in the list 135 self.failIf(item.text == 'test_folder')
136 137 138 test_model = StupidModel() 139 test_model.activity = self.xmlmenu 140 menu_config = { 141 'DefaultDirsIcon' : 'dir_icon', 142 'DefaultFilesIcon' : 'file_icon', 143 'MediaFilter' : 'ANY', 144 'ContentType' : 'sections' } 145 self.xmlmenu._model_configs[test_model] = menu_config 146 dfr = self.component.build_menu_entry(test_model, root) 147 dfr.addCallback(done_callback, test_model) 148 return dfr 149 150 # FIXME: add XDG/Windows-XDG-test, anybody an Idea, how to test it proper? 151
152 - def test_bus_messages(self):
153 154 a = bus_message.MediaLocation.ActionType.LOCATION_ADDED 155 156 # Test, if the messages got set correctly 157 self.component._locations = [] 158 d = bus_message.DeviceAction(a,'','','file:///') 159 self.component._got_bus_message(d, self) 160 location = self.component._locations[0] 161 self.assertEquals(location.location_type, 'device') 162 163 self.component._locations = [] 164 d = bus_message.ForeignApplication(a,'','','file:///') 165 self.component._got_bus_message(d, self) 166 location = self.component._locations[0] 167 self.assertEquals(location.location_type, 'app') 168 169 self.component._locations = [] 170 d = bus_message.InternetLocation(a,'','','file:///') 171 self.component._got_bus_message(d, self) 172 location = self.component._locations[0] 173 self.assertEquals(location.location_type, 'internet') 174 175 self.component._locations = [] 176 d = bus_message.LocalNetworkLocation(a,'','','file:///') 177 self.component._got_bus_message(d, self) 178 location = self.component._locations[0] 179 self.assertEquals(location.location_type, 'network') 180 181 # Let's also see, if all attributes get set correctly: 182 183 184 self.component._locations = [] 185 d = bus_message.LocalNetworkLocation(a,'b','c','file:///', 186 theme_icon='theme', 187 media_types=['hehe'],) 188 self.component._got_bus_message(d, self) 189 location = self.component._locations[0] 190 self.assertEquals(location.location_type, 'network') 191 self.assertEquals(unicode(location.uri), u'file:///') 192 self.assertEquals(location.theme_icon, 'theme') 193 self.assertEquals(location.media_types, ['hehe']) 194 195 # and remove it again 196 d.action = bus_message.MediaLocation.ActionType.LOCATION_REMOVED 197 self.component._got_bus_message(d, self) 198 self.assertEquals(self.component._locations, [])
199