def test_send_wms(client, mocker): getter = mocker.patch('requests.get') poster = mocker.patch('requests.post') urlopen = mocker.patch('urllib.request.urlopen') post = Post('note') post.content = 'This note links to [wikipedia](https://en.wikipedia.org/wiki/Webmention)' post.content_html = 'This note links to <a href="https://en.wikipedia.org/wiki/Webmention">wikipedia</a>' post.path = '2014/11/wm-sender-test' db.session.add(post) db.session.commit() urlopen.return_value = FakeUrlOpen( info=FakeUrlMetadata(content_type='text/html', content_length=256)) getter.return_value = FakeResponse(text="""<!DOCTYPE html> <html> <link rel="webmention" href="https://en.wikipedia.org/endpoint"> </html>""") wm_sender.do_send_webmentions(post.id) getter.assert_called_with('https://en.wikipedia.org/wiki/Webmention') poster.assert_called_with('https://en.wikipedia.org/endpoint', data={ 'source': post.permalink, 'target': 'https://en.wikipedia.org/wiki/Webmention', }, headers={ 'content-type': 'application/x-www-form-urlencoded', 'accept': 'application/json', })
def source_post(app, db): post = Post('note') post.content = 'This note links to [wikipedia](https://en.wikipedia.org/wiki/Webmention)' post.content_html = 'This note links to <a href="https://en.wikipedia.org/wiki/Webmention">wikipedia</a>' post.path = '2014/11/wm-sender-test' db.session.add(post) db.session.commit() return post