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

Source Code for Module elisa.core.tests.test_application

  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 config, plugin_registry 
 18  from elisa.core.application import Application 
 19  from elisa.core.application import DEFAULT_CONFIG, CONFIG_DIR, CONFIG_FILE 
 20  import os 
 21   
22 -class TestApplication(ElisaTestCase):
23 test_conf = "test.conf" 24
25 - def setUp(self):
26 ElisaTestCase.setUp(self) 27 self.app = Application('test.conf')
28
29 - def test_default_config(self):
30 """ Load the default config file 31 """ 32 try: 33 os.unlink('test.conf') 34 except: 35 pass 36 37 default_config = DEFAULT_CONFIG % {'version': 'test', 38 'install_date': 'none'} 39 c = config.Config('test.conf', default_config) 40 self.assertEqual(c.get_filename(), 'test.conf') 41 self.assertEqual(c.get_config_dir(), os.getcwd()) 42 c.write() 43 f = open('test.conf') 44 self.assertEqual(f.read(), default_config)
45
46 - def test_create_config_dir(self):
47 """ 48 """ 49 default = CONFIG_DIR 50 self.failUnless(os.path.exists(default)) 51 52 # pity this doesn't work! 53 # os.renames(default, '.elisa.bak') 54 os.system('mv %s %s' % (default, '.elisa.bak')) 55 56 57 f = os.path.join(CONFIG_DIR,CONFIG_FILE) 58 os.makedirs(CONFIG_DIR) 59 c = config.Config(f) 60 c.write() 61 62 self.failUnless(os.path.exists(default)) 63 64 #os.renames('.elisa.bak', default) 65 os.system('mv %s %s' % ('.elisa.bak/*', default)) 66 os.system('rm -fr %s' % '.elisa.bak')
67 68 test_create_config_dir.skip = "Shall we really interact with the developer's filesystem ?" 69 70
71 - def test_attributes(self):
72 73 self.failUnless(isinstance(self.app.config, config.Config)) 74 self.failUnless(isinstance(self.app.plugin_registry, 75 plugin_registry.PluginRegistry))
76 # TODO: test all other attributes: interface_controller, *_manager 77 78
79 - def test_start_stop(self):
80 81 self.app.start() 82 83 self.assertEquals(self.app.running, True) 84 85 def stopped(r): 86 self.assertEquals(self.app.running, False) 87 stopped.called = True
88 89 stopped.called = False 90 91 dfr = self.app.stop(stop_reactor=False) 92 dfr.addCallback(stopped) 93 dfr.addCallback(lambda r: self.check_called(stopped)) 94 return dfr
95
96 - def test_restart(self):
97 """ 98 This one is tricky because application.restart() spawns a new process 99 100 """ 101 self.app.start() 102 103 def restarted(r): 104 self.assertEquals(self.app.running, True) 105 restarted.called = True
106 107 restarted.called = False 108 109 dfr = self.app.restart() 110 111 # FIXME: restore this if app.stop() one day returns a Deferred 112 restarted(True) 113 self.check_called(restarted) 114 ## dfr.addCallback(restarted) 115 ## dfr.addCallback(self.check_called, restarted) 116 ## return dfr 117 test_restart.skip = "should go in a integration test" 118