switch to using Response.get_or_create()

also test an incoming activitypub like with an id with a fragment
pull/27/head
Ryan Barrett 2017-10-11 21:12:39 -07:00
rodzic d74e6f02dd
commit ef89af7372
5 zmienionych plików z 17 dodań i 16 usunięć

Wyświetl plik

@ -86,7 +86,7 @@ class InboxHandler(webapp2.RequestHandler):
obj = activity.get('object')
obj_url = util.get_url(obj)
targets = set(util.get_list(activity, 'inReplyTo'))
targets = set(util.get_list(activity, 'inReplyTo') + [obj_url])
if isinstance(obj, dict):
if not source:
source = obj_url or obj.get('id')
@ -95,16 +95,17 @@ class InboxHandler(webapp2.RequestHandler):
if not source:
self.abort(400, "Couldn't find source URL or id")
if obj_url:
targets.add(obj_url)
targets = util.dedupe_urls(targets)
if not targets:
self.abort(400, "Couldn't find target URL (inReplyTo or object)")
errors = []
for target in targets:
response = Response.get_or_insert(
'%s %s' % (source, target), direction='in', protocol='activitypub',
if not target:
continue
response = Response.get_or_create(
source=source, target=target, direction='in', protocol='activitypub',
source_as2=json.dumps(activity))
wm_source = (response.proxy_url() if type in ('Like', 'Announce')

Wyświetl plik

@ -71,8 +71,8 @@ class SlapHandler(webapp2.RequestHandler):
# send webmentions!
errors = []
for target in targets:
response = Response.get_or_insert(
'%s %s' % (source, target), direction='in', protocol='ostatus',
response = Response.get_or_create(
source=source, target=target, direction='in', protocol='ostatus',
source_atom=data)
logging.info('Sending webmention from %s to %s', source, target)
wm = send.WebmentionSend(source, target)

Wyświetl plik

@ -110,7 +110,7 @@ class ActivityPubTest(testutil.TestCase):
# (reposts are very similar)
as2_like = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': 'http://this/like',
'id': 'http://this/like#ok',
'type': 'Like',
'object': 'http://orig/post',
'actor': 'http://this/author',
@ -126,11 +126,11 @@ class ActivityPubTest(testutil.TestCase):
self.assertEquals(('http://orig/webmention',), args)
self.assertEquals({
# TODO
'source': 'http://localhost/render?source=http%3A%2F%2Fthis%2Flike&target=http%3A%2F%2Forig%2Fpost',
'source': 'http://localhost/render?source=http%3A%2F%2Fthis%2Flike__ok&target=http%3A%2F%2Forig%2Fpost',
'target': 'http://orig/post',
}, kwargs['data'])
resp = Response.get_by_id('http://this/like http://orig/post')
resp = Response.get_by_id('http://this/like__ok http://orig/post')
self.assertEqual('in', resp.direction)
self.assertEqual('activitypub', resp.protocol)
self.assertEqual('complete', resp.status)

Wyświetl plik

@ -62,7 +62,7 @@ class WebmentionTest(testutil.TestCase):
self.reply_mf2 = mf2py.parse(self.reply_html, url='http://a/reply')
self.reply_obj = microformats2.json_to_object(self.reply_mf2['items'][0])
article = requests_response({
self.article = requests_response({
'@context': ['https://www.w3.org/ns/activitystreams'],
'type': 'Article',
'content': 'Lots of ☕ words...',
@ -70,13 +70,13 @@ class WebmentionTest(testutil.TestCase):
'url': 'http://orig/author',
},
})
actor = requests_response({
self.actor = requests_response({
'objectType' : 'person',
'displayName': 'Mrs. ☕ Foo',
'url': 'https://foo.com/about-me',
'inbox': 'https://foo.com/inbox',
})
self.activitypub_gets = [self.reply, article, actor]
self.activitypub_gets = [self.reply, self.article, self.actor]
self.as2_create = {
'@context': 'https://www.w3.org/ns/activitystreams',

Wyświetl plik

@ -68,8 +68,8 @@ class WebmentionHandler(webapp2.RequestHandler):
return self.send_salmon(source_obj, target_url=target_url)
raise
self.response = Response.get_or_insert(
'%s %s' % (source_url, target_url), direction='out',
self.response = Response.get_or_create(
source=source_url, target=target_url, direction='out',
source_mf2=json.dumps(mf2))
if resp.headers.get('Content-Type').startswith('text/html'):
return self.send_salmon(source_obj, target_resp=resp)