def testMagicDirForRootGivesThatApp(self): os.mkdir(os.sep.join(['root', '__'])) app = open(os.sep.join(['root', '__', 'app.py']), 'w') app.write(DUMMY_APP + 'root = True') app.close() config = load_app(self.siteroot, '/') self.assert_(config.site_root)
def __init__(self, argv=[]): # Read them in reverse order because any file path will be in opts. # ================================================================= opts, path = self._opts(argv) file_ = self._file(path) env = self._env() defaults = self._defaults() # If we make it this far without an exception then we have clean data. # ==================================================================== # So now it's time to collate all our configuration, and store it in # useful places. Some goes on self, to be passed to Server.__init__. # A couple others are put in the environment. config = {} config.update(defaults) config.update(env) config.update(file_) config.update(opts) self.ip = config['ip'] self.port = config['port'] self.root = config['root'] self.apps = config['apps'] os.environ["HTTPY_VERBOSITY"] = str(config['verbosity']) os.environ["HTTPY_MODE"] = str(config['mode']) # Influence sys.path. # ===================================================== # We stick site_packages in sys.path whether it exists or not, because # otherwise we have to factor root app validation back out of # load_app. site_packages = os.path.join(self.root, '__', 'site-packages') sys.path.insert(0, site_packages) if self.apps_unset: self.apps = utils.find_apps(self.root) if '/' not in self.apps: self.apps += ('/', ) apps = [] for app_uri_root in self.apps: apps.append(utils.load_app(self.root, app_uri_root)) self.apps = apps
def testAppsCanCoexist(self): app1 = load_app(self.siteroot, '/app1') app3 = load_app(self.siteroot, '/app3') self.assertNotEqual(app1.num, app3.num)
def testNoMagicDirForRootGivesDefaultApp(self): config = load_app(self.siteroot, '/') expected = "<default httpy app>" actual = str(config) self.assertEqual(expected, actual)
def testBasic(self): config = load_app(self.siteroot, '/app1') expected = "</app1.Application instance at" # 0x84aa66c>" actual = str(config) self.assert_(actual.startswith(expected))