def setUp(self): self.test_path = 'tests/output/' self.manager = Manager(self.test_path) self.config_files = ConfigFiles(self.test_path) self.config_files.global_writer(DEFAULT_TEST_ARGS) self.config_files.backend_writer(DEFAULT_TEST_ARGS) self.config_files.frontend_writer(DEFAULT_TEST_ARGS)
def conf(ftype, fname): """ For PUT opts must be: {"arg1":1, "arg2":2} """ manager = Manager(config.get("haproxyfiles", "conf_files")) response = {"message": ""} if request.method == "GET": return jsonify(manager.get(ftype, fname)) elif request.method == "PUT": manager.update(ftype, fname, request.json) return jsonify(response) elif request.method == "DELETE": return jsonify(manager.delete(ftype, fname))
def setUp(self): self.test_path = "tests/output/" self.manager = Manager(self.test_path) self.config_files = ConfigFiles(self.test_path) self.config_files.global_writer(DEFAULT_TEST_ARGS) self.config_files.backend_writer(DEFAULT_TEST_ARGS) self.config_files.frontend_writer(DEFAULT_TEST_ARGS)
def conf(ftype, fname): """ For PUT opts must be: {"arg1":1, "arg2":2} """ manager = Manager(config.get("haproxyfiles", "conf_files")) response = {"message": ""} if request.method == 'GET': return jsonify(manager.get(ftype, fname)) elif request.method == 'PUT': manager.update(ftype, fname, request.json) return jsonify(response) elif request.method == 'DELETE': return jsonify(manager.delete(ftype, fname))
class ManagerTest(unittest.TestCase): def setUp(self): self.test_path = 'tests/output/' self.manager = Manager(self.test_path) self.config_files = ConfigFiles(self.test_path) self.config_files.global_writer(DEFAULT_TEST_ARGS) self.config_files.backend_writer(DEFAULT_TEST_ARGS) self.config_files.frontend_writer(DEFAULT_TEST_ARGS) def tearDown(self): filelist = glob.glob(self.test_path + "/*.cfg") for f in filelist: os.remove(f) def test_list(self): file_list = [ { "name": "machine0001" }, ] self.assertEqual(self.manager.list("frontend"), file_list) def test_get(self): ftype, fname = "frontend", "machine0001" self.config_files.frontend_writer(DEFAULT_TEST_ARGS) self.assertNotEqual(len(self.manager.get(ftype, fname)), 0) def test_get_empty_value_for_nonexistant_config(self): ftype, fname = "frontend", "invalid0001" self.assertEqual(self.manager.get(ftype, fname), {}) def test_delete(self): ftype, fname = "frontend", "machine0001" self.config_files.frontend_writer(DEFAULT_TEST_ARGS) self.manager.delete(ftype, fname) def test_update(self): ftype, fname = "frontend", "machine0001" self.manager.update(ftype, fname, {"mode": "udp"})
class ManagerTest(unittest.TestCase): def setUp(self): self.test_path = 'tests/output/' self.manager = Manager(self.test_path) self.config_files = ConfigFiles(self.test_path) self.config_files.global_writer(DEFAULT_TEST_ARGS) self.config_files.backend_writer(DEFAULT_TEST_ARGS) self.config_files.frontend_writer(DEFAULT_TEST_ARGS) def tearDown(self): filelist = glob.glob(self.test_path + "/*.cfg") for f in filelist: os.remove(f) def test_list(self): file_list = [ {"name": "machine0001"}, ] self.assertEqual(self.manager.list("frontend"), file_list) def test_get(self): ftype, fname = "frontend", "machine0001" self.config_files.frontend_writer(DEFAULT_TEST_ARGS) self.assertNotEqual(len(self.manager.get(ftype, fname)), 0) def test_get_empty_value_for_nonexistant_config(self): ftype, fname = "frontend", "invalid0001" self.assertEqual(self.manager.get(ftype, fname), {}) def test_delete(self): ftype, fname = "frontend", "machine0001" self.config_files.frontend_writer(DEFAULT_TEST_ARGS) self.manager.delete(ftype, fname) def test_update(self): ftype, fname = "frontend", "machine0001" self.manager.update(ftype, fname, {"mode": "udp"})
def list(ftype): manager = Manager(config.get("haproxyfiles", "conf_files")) return flask.jsonify(manager.list(ftype))