Some tests are passing

This commit is contained in:
Thomas Sileo 2018-06-17 21:54:16 +02:00
parent 2c53573b7e
commit 781ed8efe2
3 changed files with 15 additions and 15 deletions

View file

@ -79,7 +79,7 @@ class MicroblogPubBackend(Backend):
DB.outbox.find_one( DB.outbox.find_one(
{ {
"type": ap.ActivityType.BLOCK.value, "type": ap.ActivityType.BLOCK.value,
"activity.object": as_actor.id, "activity.object": actor_id,
"meta.undo": False, "meta.undo": False,
} }
) )
@ -92,14 +92,13 @@ class MicroblogPubBackend(Backend):
# Check if the activity is owned by this server # Check if the activity is owned by this server
if iri.startswith(BASE_URL): if iri.startswith(BASE_URL):
data = DB.outbox.find_one({"remote_id": iri}) data = DB.outbox.find_one({"remote_id": iri})
if not data: if data:
raise ActivityNotFoundError(f"{iri} not found on this server") return data["activity"]
return data["activity"] else:
# Check if the activity is stored in the inbox
# Check if the activity is stored in the inbox data = DB.inbox.find_one({"remote_id": iri})
data = DB.inbox.find_one({"remote_id": iri}) if data:
if data: return data["activity"]
return data["activity"]
# Fetch the URL via HTTP # Fetch the URL via HTTP
return super().fetch_iri(iri) return super().fetch_iri(iri)
@ -142,7 +141,7 @@ class MicroblogPubBackend(Backend):
@ensure_it_is_me @ensure_it_is_me
def new_following(self, as_actor: ap.Person, follow: ap.Follow) -> None: def new_following(self, as_actor: ap.Person, follow: ap.Follow) -> None:
remote_actor = follow.get_actor().id remote_actor = follow.get_object().id
if DB.following.find({"remote_actor": remote_actor}).count() == 0: if DB.following.find({"remote_actor": remote_actor}).count() == 0:
DB.following.insert_one({"remote_actor": remote_actor}) DB.following.insert_one({"remote_actor": remote_actor})

10
app.py
View file

@ -384,7 +384,7 @@ def authorize_follow():
if DB.following.find({"remote_actor": actor}).count() > 0: if DB.following.find({"remote_actor": actor}).count() > 0:
return redirect("/following") return redirect("/following")
follow = activitypub.Follow(actor=MY_PERSON, object=actor) follow = activitypub.Follow(actor=MY_PERSON.id, object=actor)
OUTBOX.post(follow) OUTBOX.post(follow)
return redirect("/following") return redirect("/following")
@ -1182,7 +1182,7 @@ def api_upload():
content = request.args.get("content") content = request.args.get("content")
to = request.args.get("to") to = request.args.get("to")
note = ap.Note( note = ap.Note(
actor=MY_PERSON, attributedTo=MY_PERSON.id,
cc=[ID + "/followers"], cc=[ID + "/followers"],
to=[to if to else ap.AS_PUBLIC], to=[to if to else ap.AS_PUBLIC],
content=content, # TODO(tsileo): handle markdown content=content, # TODO(tsileo): handle markdown
@ -1225,7 +1225,7 @@ def api_new_note():
cc.append(tag["href"]) cc.append(tag["href"])
note = ap.Note( note = ap.Note(
actor=MY_PERSON, attributedTo=MY_PERSON.id,
cc=list(set(cc)), cc=list(set(cc)),
to=[to if to else ap.AS_PUBLIC], to=[to if to else ap.AS_PUBLIC],
content=content, content=content,
@ -1261,7 +1261,7 @@ def api_block():
if existing: if existing:
return _user_api_response(activity=existing["activity"]["id"]) return _user_api_response(activity=existing["activity"]["id"])
block = ap.Block(actor=MY_PERSON, object=actor) block = ap.Block(actor=MY_PERSON.id, object=actor)
OUTBOX.post(block) OUTBOX.post(block)
return _user_api_response(activity=block.id) return _user_api_response(activity=block.id)
@ -1276,7 +1276,7 @@ def api_follow():
if existing: if existing:
return _user_api_response(activity=existing["activity"]["id"]) return _user_api_response(activity=existing["activity"]["id"])
follow = ap.Follow(actor=MY_PERSON, object=actor) follow = ap.Follow(actor=MY_PERSON.id, object=actor)
OUTBOX.post(follow) OUTBOX.post(follow)
return _user_api_response(activity=follow.id) return _user_api_response(activity=follow.id)

View file

@ -1,3 +1,4 @@
git+https://github.com/tsileo/little-boxes.git
pytest pytest
requests requests
html2text html2text