def setUp(self): self.config = CommandConfig() self.init = CommandInit() self.opt = FakeOptions(app_path="./newapp", wsgi_app="app.frontends.wsgi.application",\ debug=True, no_daemon=True, workers=8, keep_alive=True, chroot=True,\ recv="tcp://127.0.0.1:7000", send="tcp://127.0.0.1:7001", no_debug=False, no_chroot=False, no_keep_alive=False) os.system("rm -rf ./newapp/") self.init.run(self.opt)
class CommandConfigTest(unittest.TestCase): def setUp(self): self.config = CommandConfig() self.init = CommandInit() self.opt = FakeOptions(app_path="./newapp", wsgi_app="app.frontends.wsgi.application",\ debug=True, no_daemon=True, workers=8, keep_alive=True, chroot=True,\ recv="tcp://127.0.0.1:7000", send="tcp://127.0.0.1:7001", no_debug=False, no_chroot=False, no_keep_alive=False) os.system("rm -rf ./newapp/") self.init.run(self.opt) ''' if ${app-path}/wsgid.json does not exists, create ''' def test_create_json_if_not_exist(self): self.config.run(self.opt) self.assertTrue(os.path.exists("newapp/wsgid.json")) ''' An option passed on the command line, overrides the same option in the config file. ''' def test_override_option(self): # Write an config file so we can override some options f = file("./newapp/wsgid.json", "w+") simplejson.dump({"recv": "tcp://127.0.0.1:3000", "debug": "True", "workers": "8", "chroot": "True"}, f) f.close() # Here we override some options self.opt.recv ="tcp://127.0.0.1:4000" self.opt.workers = 8 self.opt.chroot = None # Run the config command self.config.run(self.opt) # Check that the options passed on the command line are the new config options h = simplejson.loads(file("./newapp/wsgid.json", "r+").read()) self.assertEquals("tcp://127.0.0.1:4000", h['recv']) self.assertEquals("True", h['debug']) self.assertEquals("8", h['workers']) self.assertEquals("True", h['chroot']) # An option nos passed on the command line should remain on the config file def test_create_all_options(self): opt = FakeOptions(app_path="./newapp", wsgi_app="app.frontends.wsgi.application",\ debug=True, no_daemon=True, workers=8, keep_alive=True, chroot=True,\ recv="tcp://127.0.0.1:7000", send="tcp://127.0.0.1:7001", no_debug=False, no_chroot=False, no_keep_alive=False) self.config.run(opt) h = simplejson.loads(file("./newapp/wsgid.json", "r+").read()) self.assertEquals("app.frontends.wsgi.application", h['wsgi_app']) self.assertEquals("True", h['debug']) self.assertEquals("8", h['workers']) self.assertEquals("True", h['keep_alive']) self.assertEquals("True", h['chroot']) self.assertEquals("tcp://127.0.0.1:7000", h['recv']) self.assertEquals("tcp://127.0.0.1:7001", h['send']) ''' the no_debug options is an extra option added by the config command ''' def test_disable_boolean_option(self): opt = FakeOptions(app_path="./newapp", wsgi_app="app.frontends.wsgi.application",\ no_debug=True, debug=True, workers=9, keep_alive=True, chroot=True,\ recv="tcp://127.0.0.1:7000", send="tcp://127.0.0.1:7001", no_chroot=False, no_keep_alive=False) self.config.run(opt) h = simplejson.loads(file("./newapp/wsgid.json", "r+").read()) self.assertEquals("app.frontends.wsgi.application", h['wsgi_app']) self.assertEquals("False", h['debug'])