Package elisa :: Package core :: Package tests :: Module test_metadata_manager
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.tests.test_metadata_manager

  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.elisa_test_case import ElisaTestCase 
 17  from elisa.core import plugin 
 18  from elisa.core import media_manager, metadata_manager, media_uri 
 19  from elisa.core import media_db, media_scanner 
 20  from elisa.base_components import media_provider, metadata_provider 
 21  from elisa.core.tests.test_metadata_provider import FooMetadataProvider, BarMetadataProvider 
 22   
 23  from twisted.internet import defer, threads 
 24   
25 -class GooMetadataProvider(metadata_provider.MetadataProvider):
26
27 - def get_rank(self):
28 rank = 0 29 return rank
30
31 - def able_to_handle(self, dict):
32 if not dict.has_key('uri'): 33 return False 34 35 uri = dict['uri'] 36 37 if uri.scheme == 'goo': 38 return True 39 return False
40
41 - def get_metadata(self, dict, low_priority=False):
42 d = threads.deferToThread(self._get_metadata,dict) 43 return d
44
45 - def _get_metadata(self, dict):
46 if not dict.has_key('uri'): 47 return dict 48 dict['artist'] = 'Foo' 49 dict['album'] = 'Bar' 50 return dict
51 52
53 -class FooPlugin(plugin.Plugin):
54 name = 'foo' 55 components = {'foo_meta': {'path':FooMetadataProvider}, 56 'goo_meta': {'path':GooMetadataProvider} 57 }
58
59 -class BarPlugin(plugin.Plugin):
60 name = 'bar' 61 components = {'bar_meta': {'path':BarMetadataProvider}}
62 63 64
65 -class TestMetadataManager(ElisaTestCase):
66
67 - def setUp(self):
68 ElisaTestCase.setUp(self) 69 70 # Silly 71 from elisa.core.common import application 72 registry = application.plugin_registry 73 registry.register_plugin(FooPlugin) 74 registry.register_plugin(BarPlugin) 75 76 self._manager = metadata_manager.MetadataManager() 77 self._manager.register_component(registry.create_component('foo:foo_meta')) 78 self._manager.register_component(registry.create_component('foo:goo_meta')) 79 self._manager.register_component(registry.create_component('bar:bar_meta'))
80
82 bar_uri = media_uri.MediaUri(u'bar://foo') 83 bar_dict = {'uri' : bar_uri, 'album' : None} 84 85 def callIn(dict): 86 self.assertEquals(dict, {'uri' : bar_uri, 'album': 'bar', 87 'cover': 'fool', 'artist': 'foo'})
88 89 90 df = self._manager.get_metadata(bar_dict) 91 df.addCallback(callIn) 92 return df
93
94 - def test_metadata_retrieval_foo(self):
95 bar_uri = media_uri.MediaUri(u'foo://bar') 96 bar_dict = {'uri' : bar_uri, 'artist' : None, 'album' : None} 97 98 def callIn(dict): 99 self.assertEquals(dict, {'uri' : bar_uri, 'artist' : 'foo', 100 'album': 'bar'})
101 102 103 df = self._manager.get_metadata(bar_dict) 104 df.addCallback(callIn) 105 return df 106
107 - def test_metadata_retrieval_cover(self):
108 bar_uri = media_uri.MediaUri(u'foo://bar') 109 bar_dict = {'uri' : bar_uri, 'artist' : None, 'album' : None, 110 'cover': None} 111 112 def callIn(dict): 113 self.assertEquals(dict, {'uri' : bar_uri, 'artist' : 'foo', 114 'album': 'bar', 'cover' : 'fool'})
115 116 df = self._manager.get_metadata(bar_dict) 117 df.addCallback(callIn) 118 return df 119