diff --git a/creopyson/server.py b/creopyson/server.py index 730a6dd..6f7f094 100644 --- a/creopyson/server.py +++ b/creopyson/server.py @@ -2,6 +2,7 @@ import requests import json +import re def pwd(client): @@ -24,12 +25,9 @@ def pwd(client): "function": "pwd", } # ask `http://localhost:9056/server` vs `http://localhost:9056/creoson` - list_adress = client.server.split('/')[:-1] - list_adress.append('server') - server_adress = "/".join(list_adress) - server_adress = client.server.replace("creoson", "server") + server_adress = re.sub(r'creoson$', 'server', client.server) r = requests.post(server_adress, data=json.dumps(request)) - json_result = json.loads(r.content) + json_result = r.json() status = json_result["status"]["error"] if not status: diff --git a/tests/test_server.py b/tests/test_server.py index b502fa6..a901cb0 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -12,8 +12,7 @@ class Mk_post(): def __init__(self, *args, **kwargs): pass - @property - def content(self): + def json(self): results = { "status": { "error": False, @@ -22,7 +21,7 @@ def content(self): "dirname": "C:/CreosonServer-2.3.0-win64" } } - return json.dumps(results).encode() + return results monkeypatch.setattr(requests, 'post', Mk_post) c = creopyson.Client() @@ -36,15 +35,14 @@ class Mk_post(): def __init__(self, *args, **kwargs): pass - @property - def content(self): + def json(self): results = { "status": { "error": True, "message": "error message" } } - return json.dumps(results).encode() + return results monkeypatch.setattr(requests, 'post', Mk_post) c = creopyson.Client()