render: support atom

pull/27/head
Ryan Barrett 2017-10-15 10:50:01 -07:00
rodzic c2a3444ba2
commit f119b02f18
2 zmienionych plików z 23 dodań i 4 usunięć

Wyświetl plik

@ -4,7 +4,7 @@ import json
import appengine_config
from granary import as2, microformats2
from granary import as2, atom, microformats2
from oauth_dropins.webutil.handlers import ModernHandler
from oauth_dropins.webutil import util
import webapp2
@ -29,7 +29,7 @@ class RenderHandler(ModernHandler):
elif resp.source_as2:
as1 = as2.to_as1(json.loads(resp.source_as2))
elif resp.source_atom:
self.abort(501, 'Rendering HTML from Atom is not yet implemented.')
as1 = atom.atom_to_activity(resp.source_atom)
else:
self.abort(404, 'Stored response for %s has no data' % id)

Wyświetl plik

@ -16,25 +16,37 @@ class RenderTest(testutil.TestCase):
self.as2 = {
'@context': 'https://www.w3.org/ns/activitystreams',
'type': 'Note',
'content': 'A ☕ reply',
'id': 'http://this/reply',
'url': 'http://this/reply',
'content': 'A ☕ reply',
'inReplyTo': 'http://orig/post',
}
self.mf2 = {
'type': ['h-entry'],
'properties': {
'uid': ['http://this/reply'],
'url': ['http://this/reply'],
'content': [{'value': 'A ☕ reply'}],
'in-reply-to': ['http://orig/post'],
},
}
self.atom = """\
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0">
<uri>http://this/reply</uri>
<thr:in-reply-to href="http://orig/post" />
<content>A reply</content>
</entry>
"""
self.html = """\
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"></head>
<body>
<article class="h-entry">
<span class="p-uid"></span>
<span class="p-uid">http://this/reply</span>
<a class="u-url" href="http://this/reply">http://this/reply</a>
<div class="e-content p-name">
A reply
@ -72,3 +84,10 @@ class RenderTest(testutil.TestCase):
self.assertEquals(200, resp.status_int)
self.assert_multiline_equals(self.html, resp.body.decode('utf-8'),
ignore_blanks=True)
def test_render_atom(self):
Response(id='abc xyz', source_atom=self.atom).put()
resp = app.get_response('/render?source=abc&target=xyz')
self.assertEquals(200, resp.status_int)
self.assert_multiline_equals(self.html, resp.body.decode('utf-8'),
ignore_blanks=True)