Loading src/tests/tools/mock_qkd_node/wsgi.py +54 −33 Original line number Diff line number Diff line Loading @@ -124,33 +124,6 @@ def edit(from_dict, to_dict, create): else: to_dict[key] = value def edit_side_effect(url, json, create): steps = url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: raise ValueError(f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}") ip_port, _, _, header, *steps = parts module, root = header.split(':') assert(module == 'etsi-qkd-sdn-node') assert(root == 'qkd_node') if not steps: edit(json, nodes[ip_port]['node'], create) return endpoint, *steps = steps if not steps: edit(json[endpoint], nodes[ip_port][endpoint], create) return raise Exception('Url too long') @app.get('/', defaults={'path': ''}) @app.get("/<string:path>") @app.get('/<path:path>') Loading @@ -167,14 +140,35 @@ def get(path): @app.post("/<string:path>") @app.post('/<path:path>') def post(path): success = True reason = '' try: edit_side_effect(request.base_url, request.json, True) steps = request.base_url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: return {'success': False, 'reason': f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}"} ip_port, _, _, header, *steps = parts module, root = header.split(':') assert module == 'etsi-qkd-sdn-node' assert root == 'qkd_node' if not steps: edit(request.json, nodes[ip_port]['node'], True) return {'success': True, 'reason': ''} endpoint, *steps = steps if not steps: edit(request.json[endpoint], nodes[ip_port][endpoint], True) return {'success': True, 'reason': ''} return {'success': False, 'reason': 'Url too long'} except Exception as e: reason = str(e) success = False return {'success': success, 'reason': reason} return {'success': False, 'reason': str(e)} @app.route('/', defaults={'path': ''}, methods=['PUT', 'PATCH']) @app.route("/<string:path>", methods=['PUT', 'PATCH']) Loading @@ -184,6 +178,33 @@ def patch(path): reason = '' try: edit_side_effect(request.base_url, request.json, False) def edit_side_effect(url, json, create): steps = url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: raise ValueError(f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}") ip_port, _, _, header, *steps = parts module, root = header.split(':') assert(module == 'etsi-qkd-sdn-node') assert(root == 'qkd_node') if not steps: edit(json, nodes[ip_port]['node'], create) return endpoint, *steps = steps if not steps: edit(json[endpoint], nodes[ip_port][endpoint], create) return raise Exception('Url too long') except Exception as e: reason = str(e) success = False Loading Loading
src/tests/tools/mock_qkd_node/wsgi.py +54 −33 Original line number Diff line number Diff line Loading @@ -124,33 +124,6 @@ def edit(from_dict, to_dict, create): else: to_dict[key] = value def edit_side_effect(url, json, create): steps = url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: raise ValueError(f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}") ip_port, _, _, header, *steps = parts module, root = header.split(':') assert(module == 'etsi-qkd-sdn-node') assert(root == 'qkd_node') if not steps: edit(json, nodes[ip_port]['node'], create) return endpoint, *steps = steps if not steps: edit(json[endpoint], nodes[ip_port][endpoint], create) return raise Exception('Url too long') @app.get('/', defaults={'path': ''}) @app.get("/<string:path>") @app.get('/<path:path>') Loading @@ -167,14 +140,35 @@ def get(path): @app.post("/<string:path>") @app.post('/<path:path>') def post(path): success = True reason = '' try: edit_side_effect(request.base_url, request.json, True) steps = request.base_url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: return {'success': False, 'reason': f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}"} ip_port, _, _, header, *steps = parts module, root = header.split(':') assert module == 'etsi-qkd-sdn-node' assert root == 'qkd_node' if not steps: edit(request.json, nodes[ip_port]['node'], True) return {'success': True, 'reason': ''} endpoint, *steps = steps if not steps: edit(request.json[endpoint], nodes[ip_port][endpoint], True) return {'success': True, 'reason': ''} return {'success': False, 'reason': 'Url too long'} except Exception as e: reason = str(e) success = False return {'success': success, 'reason': reason} return {'success': False, 'reason': str(e)} @app.route('/', defaults={'path': ''}, methods=['PUT', 'PATCH']) @app.route("/<string:path>", methods=['PUT', 'PATCH']) Loading @@ -184,6 +178,33 @@ def patch(path): reason = '' try: edit_side_effect(request.base_url, request.json, False) def edit_side_effect(url, json, create): steps = url.lstrip('https://').lstrip('http://').rstrip('/') parts = steps.split('/') # Ensure there are enough parts to unpack if len(parts) < 4: raise ValueError(f"Expected at least 4 parts in the URL, got {len(parts)}: {steps}") ip_port, _, _, header, *steps = parts module, root = header.split(':') assert(module == 'etsi-qkd-sdn-node') assert(root == 'qkd_node') if not steps: edit(json, nodes[ip_port]['node'], create) return endpoint, *steps = steps if not steps: edit(json[endpoint], nodes[ip_port][endpoint], create) return raise Exception('Url too long') except Exception as e: reason = str(e) success = False Loading