Add tests for block, and start test for replies

This commit is contained in:
Thomas Sileo
2018-05-29 00:12:44 +02:00
parent bba598be66
commit b727c8c9c7
2 changed files with 108 additions and 6 deletions

32
app.py
View File

@@ -847,9 +847,16 @@ def api_new_note():
source = request.args.get('content')
if not source:
raise ValueError('missing content')
reply = None
if request.args.get('reply'):
reply = activitypub.parse_activity(OBJECT_SERVICE.get(request.args.get('reply')))
source = request.args.get('content')
content, tags = parse_markdown(source)
to = request.args.get('to')
cc = [ID+'/followers']
if reply:
cc.append(reply.attributedTo)
for tag in tags:
if tag['type'] == 'Mention':
cc.append(tag['href'])
@@ -857,12 +864,14 @@ def api_new_note():
note = activitypub.Note(
cc=cc,
to=[to if to else config.AS_PUBLIC],
content=content,
content=content, # TODO(tsileo): handle markdown
tag=tags,
source={'mediaType': 'text/markdown', 'content': source},
inReplyTo=reply.id if reply else None
)
create = note.build_create()
create.post_to_outbox()
return Response(
status=201,
response='OK',
@@ -877,6 +886,27 @@ def api_stream():
headers={'Content-Type': 'application/json'},
)
@app.route('/api/block')
@api_required
def api_block():
# FIXME(tsileo): ensure it's a Person ID
actor = request.args.get('actor')
if not actor:
raise ValueError('missing actor')
if DB.outbox.find_one({'type': ActivityType.BLOCK.value,
'activity.object': actor,
'meta.undo': False}):
return Response(status=201)
block = activitypub.Block(object=actor)
block.post_to_outbox()
return Response(
status=201,
headers={'Microblogpub-Created-Activity': block.id},
)
@app.route('/api/follow')
@api_required
def api_follow():