small adjustments after first feedback

This commit is contained in:
Matthias
2019-05-18 13:36:51 +02:00
parent 79cac36b34
commit e6ae890def
3 changed files with 10 additions and 16 deletions

View File

@@ -66,7 +66,6 @@ class ApiServer(RPC):
self.app.json_encoder = ArrowJSONEncoder
# Register application handling
self.register_rest_other()
self.register_rest_rpc_urls()
thread = threading.Thread(target=self.run, daemon=True)
@@ -92,13 +91,13 @@ class ApiServer(RPC):
"e.g 127.0.0.1 in config.json")
# Run the Server
logger.info('Starting Local Rest Server')
logger.info('Starting Local Rest Server.')
try:
self.srv = make_server(rest_ip, rest_port, self.app)
self.srv.serve_forever()
except Exception:
logger.exception("Api server failed to start, exception message is:")
logger.info('Starting Local Rest Server_end')
logger.exception("Api server failed to start.")
logger.info('Local Rest Server started.')
def send_msg(self, msg: Dict[str, str]) -> None:
"""
@@ -114,13 +113,6 @@ class ApiServer(RPC):
def rest_error(self, error_msg):
return jsonify({"error": error_msg}), 502
def register_rest_other(self):
"""
Registers flask app URLs that are not calls to functionality in rpc.rpc.
:return:
"""
self.app.register_error_handler(404, self.page_not_found)
def register_rest_rpc_urls(self):
"""
Registers flask app URLs that are calls to functonality in rpc.rpc.
@@ -129,6 +121,8 @@ class ApiServer(RPC):
Label can be used as a shortcut when refactoring
:return:
"""
self.app.register_error_handler(404, self.page_not_found)
# Actions to control the bot
self.app.add_url_rule(f'{BASE_URI}/start', 'start',
view_func=self._start, methods=['POST'])

View File

@@ -101,7 +101,7 @@ def test_api_run(default_conf, mocker, caplog):
assert hasattr(apiserver, "srv")
assert log_has("Starting HTTP Server at 127.0.0.1:8080", caplog.record_tuples)
assert log_has("Starting Local Rest Server", caplog.record_tuples)
assert log_has("Starting Local Rest Server.", caplog.record_tuples)
# Test binding to public
caplog.clear()
@@ -116,7 +116,7 @@ def test_api_run(default_conf, mocker, caplog):
assert server_mock.call_args_list[0][0][1] == "8089"
assert isinstance(server_mock.call_args_list[0][0][2], Flask)
assert log_has("Starting HTTP Server at 0.0.0.0:8089", caplog.record_tuples)
assert log_has("Starting Local Rest Server", caplog.record_tuples)
assert log_has("Starting Local Rest Server.", caplog.record_tuples)
assert log_has("SECURITY WARNING - Local Rest Server listening to external connections",
caplog.record_tuples)
assert log_has("SECURITY WARNING - This is insecure please set to your loopback,"
@@ -127,7 +127,7 @@ def test_api_run(default_conf, mocker, caplog):
caplog.clear()
mocker.patch('freqtrade.rpc.api_server.make_server', MagicMock(side_effect=Exception))
apiserver.run()
assert log_has("Api server failed to start, exception message is:",
assert log_has("Api server failed to start.",
caplog.record_tuples)