From 123917d641b329f41927ef0196eecbb43765e839 Mon Sep 17 00:00:00 2001 From: Pete Shadbolt Date: Sun, 15 Oct 2017 19:34:24 -0700 Subject: [PATCH] Posting data works okay --- app.py | 8 ++++---- test.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 test.py diff --git a/app.py b/app.py index ce37e90..fae02ca 100644 --- a/app.py +++ b/app.py @@ -10,20 +10,20 @@ def index(): return render_template("index.html") @app.route("/graph", methods=["GET", "POST"]) -def graph(page): +def graph(): if request.method == 'POST': # Convert the data to a graph state g = abp.GraphState() - g.from_json(json.loads(data)) + g.from_json(json.loads(request.data)) - # Convert it back to JSON + # Convert it back to JSON just for fun data = json.dumps(g.to_json(stringify=True)) # Insert into the database redis.execute_command("SET", "graph", data) # Return success - return "OK" + return "Posted {} bytes OK".format(len(data)) else: # Get from the database diff --git a/test.py b/test.py new file mode 100644 index 0000000..9e159a5 --- /dev/null +++ b/test.py @@ -0,0 +1,19 @@ +""" +Makes a dummy post to the test server +""" +import requests +import json +import abp + +def test_graph(): + N = 1000 + g = abp.GraphState(range(N), vop="hadamard") + for i in range(N-1): + g.act_cz(i, i+1) + return g + +if __name__ == '__main__': + data = json.dumps(test_graph().to_json()) + r = requests.post("http://localhost:5000/graph", data=data) + print r.status_code, r.content +