From c4e848c21c028ca7c52846ea1abd7f3a38aff7d6 Mon Sep 17 00:00:00 2001 From: Tom Harley Date: Sat, 10 Jul 2021 21:41:09 +0000 Subject: Add more inbox/outbox tests Still not even total coverage! Need to: - write more tests for outbox manipulation - look into and implement receiving content from other servers (+ write tests) off the top of my head. --- sw/users.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'sw/users.py') diff --git a/sw/users.py b/sw/users.py index 08302b3..71258c1 100644 --- a/sw/users.py +++ b/sw/users.py @@ -1,4 +1,4 @@ -from flask import Blueprint, jsonify, url_for, request, abort +from flask import Blueprint, jsonify, url_for, request, abort, g, Response import json @@ -45,8 +45,10 @@ def get_user_inbox(username): "select inbox_size from users where username=?", (username,) ).fetchone()[0] - if inbox_size is None: - abort(404, "User not found") + # since a logged-in user is required to access this endpoint, there + # is no way that a non-existant user can be queried (in other + # words, the user will not have the clearance to see an unreal + # user's inbox) return jsonify( { @@ -139,12 +141,12 @@ def post_user_inbox_item(username): db = get_db() time = now() - res = db.exec( - "insert into inbox (recipient, received, content) values (?,?,?) ;", - (username, time, data), + res = db.execute( + "insert into inbox (recipient, received, ap_content) values (?,?,?) ;", + (username, time, str(data)), ) - db.exec( + db.execute( "update users set inbox_size = inbox_size + 1 where id = ? ;", (g.user["id"],), ) @@ -235,7 +237,7 @@ def post_user_outbox_item(username): item_id = None if "id" not in data: res = db.exec( - "insert into items (created, updated, content) " + "insert into items (created, updated, ap_content) " "output Inserted.id " "values (?,?,?) " ";", @@ -254,7 +256,7 @@ def post_user_outbox_item(username): if not is_ap_activity(data): activity = create_wrapper(item_id) res = db.exec( - "insert into items (created, updated, content) " + "insert into items (created, updated, ap_content) " "output Inserted.id " "values (?,?,?) " ";", -- cgit v1.2.1