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

Source Code for Module elisa.core.tests.elisa_test_case

  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.extern.translation import Translator 
 17   
 18  from elisa.core import log, common 
 19  #FIXME : BAD HACK to disable the reactor installation in test mode  
 20  common.from_test = True 
 21   
 22  from elisa.core import application 
 23  from elisa.core import config, plugin_registry 
 24  from elisa.core import interface_controller 
 25  from elisa.core import media_manager 
 26  from elisa.core import metadata_manager 
 27  from elisa.core import input_manager 
 28  from elisa.core import plugin 
 29  from elisa.core.bus import bus 
 30  from elisa.base_components import view, context, activity, model, controller,\ 
 31       theme 
 32  from elisa.extern.log import log as extern_log 
 33   
 34  from twisted.trial import unittest 
 35  import os, sys, inspect 
 36   
 37   
 38   
 39  DEFAULT_CONFIG = """\ 
 40  [general] 
 41  version = '%(version)s' 
 42  install_date = '%(install_date)s' 
 43  media_providers = [] 
 44  metadata_providers = [] 
 45  service_providers = [] 
 46  player_engines = [] 
 47  backends = ['backend1'] 
 48  frontends = ['frontend1'] 
 49   
 50  [media_scanner] 
 51  enabled = '1' 
 52  db_backend = 'sqlite' 
 53  database = 'elisa.db' 
 54  fivemin_location_updates = [] 
 55  hourly_location_updates = [] 
 56  daily_location_updates = [] 
 57  weekly_location_updates = [] 
 58  unmonitored_locations = [] 
 59   
 60  [backend1] 
 61  activity = 'test:elisa_activity' 
 62  mvc_mappings = 'test_mvc_mappings.conf' 
 63  input_providers = [] 
 64   
 65  [frontend1] 
 66  backend = 'backend1' 
 67  theme = 'test:test_theme' 
 68  input_providers = [] 
 69   
 70  [xmlmenu:locations_builder] 
 71  locations = [] 
 72  auto_locations = 1 
 73   
 74  [lirc:lirc_input] 
 75  # filename of the LIRC config map to use 
 76  lirc_rc = 'streamzap.lirc' 
 77  delay = '4' 
 78  repeat = '1' 
 79   
 80  [coherence:coherence_service] 
 81  logmode = 'none' 
 82  controlpoint = 'yes' 
 83   
 84  [[plugins]] 
 85   
 86  [base:service_activity] 
 87  # a list of activites, which should beappear in the service_menu 
 88  service_activities = ['service:about_activity'] 
 89   
 90  [dvd:dvd_activity] 
 91  # uri of the dvd. must be file:///* or dvd:// 
 92  dvd_uri = 'dvd://' 
 93   
 94  [player] 
 95  audiosink = 'autoaudiosink' 
 96   
 97  [theme_switcher:theme_switcher_activity] 
 98  # a list of themes 'plugin:component' like 'classic:theme' 
 99  themes = ['poblenou:tango_theme', 'poblenou:poblenou_theme', 'poblenou:chris_theme'] 
100  """ 
101   
102   
103  MAPPINGS="""\ 
104  [test:elisa_model] 
105  supported_controllers = ['test:elisa_controller',] 
106  controller = 'test:elisa_controller' 
107  supported_views = ['test:elisa_view'] 
108  view = 'test:elisa_view' 
109  """ 
110   
111 -class TestTheme(theme.Theme):
112 name = 'test_theme'
113
114 -class TestModel(model.Model):
115 name = 'elisa_model' 116 path = 'test:elisa_model'
117
118 -class TestController(controller.Controller):
119 name = 'elisa_controller' 120 supported_models = ('test:elisa_model',)
121
122 -class TestActivity(activity.Activity):
123 name = 'elisa_activity' 124
125 - def get_model(self):
126 return TestModel()
127
128 -class TestView(view.View):
129 name = 'elisa_view' 130 context_path = 'test:elisa_context' 131 supported_controllers = ('test:elisa_controller',)
132
133 -class TestContext(context.Context):
134 name = 'elisa_context'
135
136 -class TestPlugin(plugin.Plugin):
137 name = 'test' 138 components = {'elisa_model': {'path': TestModel}, 139 'elisa_controller': {'path': TestController}, 140 'elisa_view': {'path': TestView}, 141 'elisa_context': {'path': TestContext}, 142 'elisa_activity': {'path': TestActivity}, 143 'test_theme': {'path': TestTheme}, 144 }
145
146 -class BoilerPlateApp:
147
148 - def __init__(self, config_file, default_config=None, load_all_plugins=False):
149 #self.config = config.Config(config_file) 150 if not default_config: 151 default_config = DEFAULT_CONFIG 152 self.errors = [] 153 154 default_config = default_config % {'version': 'test', 155 'install_date': 'none'} 156 self.config = config.Config('empty.conf', default_config) 157 common.set_application(self) 158 159 self.translator = Translator() 160 manager = plugin_registry.PluginRegistry(self.config) 161 if load_all_plugins: 162 manager.load_plugins() 163 manager.register_plugin(TestPlugin) 164 165 self.plugin_registry = manager 166 self.bus = bus.Bus() 167 self.media_manager = media_manager.MediaManager(None) 168 self.metadata_manager = metadata_manager.MetadataManager() 169 self.input_manager = input_manager.InputManager() 170 self.interface_controller = interface_controller.InterfaceController() 171 self.interface_controller.initialize()
172
173 - def handle_traceback(self):
174 info = sys.exc_info() 175 self.errors.append(info)
176
177 -class ElisaTestCase(unittest.TestCase, extern_log.Loggable):
178 default_config = DEFAULT_CONFIG 179 load_all_plugins = False 180
181 - def __init__(self, methodName='runTest'):
182 183 test_file_path = inspect.getsourcefile(self.__class__) 184 if test_file_path is not None: 185 fname = os.path.basename(test_file_path) 186 187 fname, _ = os.path.splitext(fname) 188 self.logCategory = fname 189 self.directory = os.path.dirname(test_file_path) 190 191 #extern_log.init('ELISA_TESTS') 192 unittest.TestCase.__init__(self, methodName=methodName)
193 194 debug = extern_log.Loggable.debug 195 info = extern_log.Loggable.info 196
197 - def setUp(self):
198 common.boot() 199 200 if 'ELISA_DEBUG' not in os.environ: 201 log.setDebug('*:0') 202 203 f = open('test_mvc_mappings.conf','w') 204 f.write(MAPPINGS) 205 f.close() 206 207 app = BoilerPlateApp('empty.conf', self.default_config, 208 self.load_all_plugins) 209 self.debug("Set common.application to %r", app)
210
211 - def check_called(self, callback):
212 self.failUnless(hasattr(callback, 'called')) 213 self.assertEquals(callback.called, True)
214