Package elisa :: Package plugins :: Package good :: Package fspot :: Package tests :: Module test_fspot_media
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.good.fspot.tests.test_fspot_media

  1  # Elisa - Home multimedia server 
  2  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  3  # All rights reserved. 
  4  # 
  5  # This file is available under one of two license agreements. 
  6  # 
  7  # This file is licensed under the GPL version 3. 
  8  # See "LICENSE.GPL" in the root of this distribution including a special 
  9  # exception to use Elisa with Fluendo's plugins. 
 10  # 
 11  # The GPL part of Elisa is also available under a commercial licensing 
 12  # agreement from Fluendo. 
 13  # See "LICENSE.Elisa" in the root directory of this distribution package 
 14  # for details on that license. 
 15   
 16  from elisa.core.tests.test_media_provider import TestMediaProvider 
 17  from elisa.core import db_backend 
 18  from elisa.core.media_uri import MediaUri 
 19  import os, platform 
 20  from twisted.internet import defer 
 21  import tempfile 
 22   
 23  # TODO: refactor next_location() tests with deferred generators. 
 24   
25 -class FspotTest(TestMediaProvider):
26 component_class = 'fspot_media:FspotMedia' 27 component_path = '..' 28 dump_path = None 29
30 - def __init__(self, methodName='runTests'):
31 TestMediaProvider.__init__(self, methodName) 32 if self.dump_path is None: 33 self.skip = "no db dump to load" 34 if platform.system() == 'Windows': 35 self.skip = "test not supported under windows"
36
37 - def setUp(self):
38 39 # load the SQL dump 40 dump_path = os.path.join(self.directory, self.dump_path) 41 fd, self._db_path = tempfile.mkstemp() 42 43 db = db_backend.DBBackend(db_backend='sqlite', database=self._db_path) 44 for statement in open(dump_path).read().split(';'): 45 db.sql_execute(statement) 46 db.save_changes() 47 db.disconnect() 48 49 self.component_class.default_config = {'db_path': self._db_path} 50 TestMediaProvider.setUp(self)
51
52 - def get_valid_uris(self):
53 return [MediaUri("fspot:///")]
54
55 - def tearDown(self):
56 TestMediaProvider.tearDown(self) 57 os.unlink(self._db_path)
58
59 -class TestKaleoFspot(FspotTest):
60 61 dump_path = 'data/kaleo.sql' 62 63
65 66 start = MediaUri("fspot:///") 67 68 def got_next1(next): 69 self.assertEquals(next, MediaUri(u'fspot:///Acontecimientos?id=5&tag_id=-1')) 70 71 dfr2 = self.component.next_location(next, root=start) 72 dfr2.addCallback(got_next2) 73 return dfr2
74 75 def got_next2(next): 76 self.assertEquals(next, MediaUri(u'fspot:///Favoritos?id=1&tag_id=-1')) 77 78 dfr = self.component.next_location(next, root=start) 79 dfr.addCallback(got_next3) 80 return dfr
81 82 def got_next3(next): 83 self.assertEquals(next, MediaUri(u'fspot:///home/kaleo/Desktop/media/pictures/NATURE-ChristmasOnMaui_1280x1024.jpg?tag_id=1#6')) 84 85 dfr = self.component.next_location(next, root=start) 86 dfr.addCallback(got_next4) 87 return dfr 88 89 def got_next4(next): 90 self.assertEquals(next, MediaUri(u'fspot:///home/kaleo/Desktop/media/pictures/Julia.png?tag_id=3#5')) 91 dfr = self.component.next_location(next, root=start) 92 dfr.addCallback(got_next5) 93 return dfr 94 95 def got_next5(next): 96 self.assertEquals(next, MediaUri(u'fspot:///home/kaleo/Desktop/media/pictures/369113572_24fc34005a_o_d.jpg?tag_id=3#2')) 97 dfr = self.component.next_location(next, root=start) 98 dfr.addCallback(got_next6) 99 return dfr 100 101 def got_next6(next): 102 self.assertEquals(next, MediaUri(u'fspot:///home/kaleo/Desktop/media/pictures/308567765_b904571e9f_o.jpg?tag_id=4#1')) 103 dfr = self.component.next_location(next, root=start) 104 dfr.addCallback(got_next7) 105 return dfr 106 107 def got_next7(next): 108 self.assertEquals(next, MediaUri(u'fspot:///home/kaleo/Desktop/media/pictures/NATURE-KosametThailand_1280x1024.jpg?tag_id=4#7')) 109 dfr = self.component.next_location(next, root=start) 110 dfr.addCallback(got_next8) 111 return dfr 112 113 def got_next8(next): 114 # TODO: finish me (or remove photos from kaleo's db) 115 self.failIf(next is None) 116 117 dfr = self.component.next_location(start, root=start) 118 dfr.addCallback(got_next1) 119 return dfr 120 121
122 -class TestFspotMedia0_3(FspotTest):
123 124 dump_path = 'data/fspot_0_3.sql' 125 126
127 - def _from_tmp_tag(self):
128 start = MediaUri("fspot:///subtmp?id=7&tag_id=6") 129 130 def got_next1(next): 131 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2001/2/17/duck.jpg?tag_id=7#19')) 132 133 dfr2 = self.component.next_location(next, root=start) 134 dfr2.addCallback(got_next2) 135 return dfr2
136 137 def got_next2(next): 138 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2001/9/26/dogs.jpg?tag_id=7#18')) 139 140 dfr = self.component.next_location(next, root=start) 141 dfr.addCallback(got_next3) 142 return dfr
143 144 def got_next3(next): 145 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2002/4/1/lambs.jpg?tag_id=7#22')) 146 got_next3.called = True 147 return next 148 149 got_next3.called = False 150 151 def check_called(uri): 152 self.check_called(got_next3) 153 return uri 154 155 dfr = self.component.next_location(start, root=start) 156 dfr.addCallback(got_next1) 157 dfr.addCallback(check_called) 158 return dfr 159
160 - def test_simple_next_location(self):
161 dfr = self._from_tmp_tag() 162 return dfr
163
164 - def test_next_location_from_root(self):
165 166 start = MediaUri("fspot:///") 167 168 def got_next1(next): 169 self.assertEquals(next, MediaUri(u'fspot:///Events?id=5&tag_id=-1')) 170 171 dfr2 = self.component.next_location(next, root=start) 172 dfr2.addCallback(got_next2) 173 return dfr2
174 175 def got_next2(next): 176 self.assertEquals(next, MediaUri(u'fspot:///Favorites?id=1&tag_id=-1')) 177 178 dfr = self.component.next_location(next, root=start) 179 dfr.addCallback(got_next3) 180 return dfr 181 182 183 def got_next3(next): 184 self.assertEquals(next, MediaUri(u'fspot:///Hidden?id=2&tag_id=-1')) 185 186 dfr = self.component.next_location(next, root=start) 187 dfr.addCallback(got_next4) 188 return dfr 189 190 def got_next4(next): 191 self.assertEquals(next, MediaUri(u'fspot:///People?id=3&tag_id=-1')) 192 193 dfr = self.component.next_location(next, root=start) 194 dfr.addCallback(got_next5) 195 return dfr 196 197 def got_next5(next): 198 self.assertEquals(next, MediaUri(u'fspot:///tmp?id=6&tag_id=3')) 199 200 dfr = self._from_tmp_tag() 201 dfr.addCallback(lambda uri: self.component.next_location(uri, 202 root=start)) 203 dfr.addCallback(got_next6) 204 return dfr 205 206 def got_next6(next): 207 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2004/7/30/rabbit.jpg?tag_id=6#25')) 208 209 dfr = self.component.next_location(next, root=start) 210 dfr.addCallback(got_next7) 211 212 return dfr 213 214 def got_next7(next): 215 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2004/7/30/rabbit.jpg?tag_id=6#10')) 216 217 dfr = self.component.next_location(next, root=start) 218 dfr.addCallback(got_next8) 219 return dfr 220 221 def got_next8(next): 222 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2006/8/22/leopard.jpg?tag_id=6#23')) 223 224 dfr = self.component.next_location(next, root=start) 225 dfr.addCallback(got_next9) 226 return dfr 227 228 def got_next9(next): 229 self.assertEquals(next, MediaUri(u'fspot:///home/phil/Photos/2003/1/29/hippo.jpg?tag_id=3#20')) 230 got_next9.called = True 231 232 got_next9.called = False 233 234 dfr = self.component.next_location(start, root=start) 235 dfr.addCallback(got_next1) 236 dfr.addCallback(lambda r: self.check_called(got_next9)) 237 return dfr 238
239 - def test_get_media_type(self):
240 241 def check_file(result): 242 self.assertEquals(result['file_type'], 'image') 243 self.assertEquals(result['mime_type'], 'image/jpeg')
244 245 u1 = MediaUri(u'fspot:///home/phil/Photos/2003/1/29/hippo.jpg?tag_id=3#20') 246 d1 = self.component.get_media_type(u1) 247 d1.addCallback(check_file) 248 249 def check_dir(result): 250 self.assertEquals(result['file_type'], 'directory') 251 self.assertEquals(result['mime_type'], '') 252 253 u2 = MediaUri(u'fspot:///tmp?id=6&tag_id=3') 254 d2 = self.component.get_media_type(u2) 255 d2.addCallback(check_dir) 256 257 d = defer.DeferredList([d1,d2]) 258 return d 259
260 - def test_has_children(self):
261 262 def check_file(result): 263 self.assertEquals(result, False)
264 265 u1 = MediaUri(u'fspot:///home/phil/Photos/2003/1/29/hippo.jpg?tag_id=3#20') 266 d1 = self.component.has_children_with_types(u1,['image',]) 267 d1.addCallback(check_file) 268 269 def check_dir(result): 270 self.assertEquals(result, True) 271 272 u2 = MediaUri(u'fspot:///tmp?id=6&tag_id=3') 273 d2 = self.component.has_children_with_types(u2, ['image',]) 274 d2.addCallback(check_dir) 275 276 def check_dir2(result): 277 self.assertEquals(result, True) 278 279 u3 = MediaUri(u'fspot:///') 280 d3 = self.component.has_children_with_types(u3, ['directory',]) 281 d3.addCallback(check_dir2) 282 283 u4 = MediaUri("fspot:///subtmp?id=7&tag_id=6") 284 d4 = self.component.has_children_with_types(u4, ['directory', 'image']) 285 d4.addCallback(check_dir2) 286 287 d = defer.DeferredList([d1,d2,d3,d4]) 288 return d 289
290 - def test_get_direct_children(self):
291 292 def got_children(children): 293 expected = ['fspot:///Events?id=5&tag_id=-1', 294 'fspot:///Favorites?id=1&tag_id=-1', 295 'fspot:///Hidden?id=2&tag_id=-1', 296 'fspot:///People?id=3&tag_id=-1', 297 'fspot:///Places?id=4&tag_id=-1'] 298 children = [ str(uri) for uri, metadata in children ] 299 self.assertEquals(expected, children)
300 301 d1 = self.component.get_direct_children(MediaUri('fspot:///'), 302 []) 303 d1.addCallback(got_children) 304 return d1 305
306 - def test_get_direct_children_tmp(self):
307 308 def got_children(children): 309 expected = ['fspot:///home/phil/Photos/2001/2/17/duck.jpg?tag_id=7#19', 310 'fspot:///home/phil/Photos/2001/9/26/dogs.jpg?tag_id=7#18', 311 'fspot:///home/phil/Photos/2002/4/1/lambs.jpg?tag_id=7#22'] 312 children = [ str(uri) for uri, metadata in children ] 313 self.assertEquals(expected, children)
314 315 d1 = self.component.get_direct_children(MediaUri("fspot:///subtmp?id=7&tag_id=6"), 316 []) 317 d1.addCallback(got_children) 318 return d1 319
320 -class TestFspotMedia0_4(TestFspotMedia0_3):
321 322 dump_path = 'data/fspot_0_4.sql'
323