def test_success(self): html = """ <article class="h-entry"> <p class="p-author">my name</p> <p class="e-content"> i hereby reply <a class="u-in-reply-to" href="http://foo.com/post/1"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', 'i hereby reply\n<a class="u-in-reply-to" href="http://foo.com/post/1"></a>' ' <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) self.assertEquals({'id': 'fake id'}, json.loads(resp.body)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals(self.source.key, bw.source) self.assertEquals('complete', bw.status) self.assertEquals('comment', bw.type) self.assertEquals(html, bw.html) self.assertEquals({'id': 'fake id'}, bw.published)
def test_rel_canonical_different_domain(self): self.expect_requests_get('http://foo.zz/post/1', """ <head> <link href='http://foo.com/post/1' rel='canonical'/> </head> foo bar""") html = """ <article class="h-entry"><p class="e-content"> <a href="http://bar.com/mention">this post</a> i hereby <a href="http://foo.zz/post/1">mention</a> </p></article>""" self.expect_requests_get('http://bar.com/mention', html) testutil.FakeSource.create_comment( 'http://foo.zz/post/1', 'foo.zz', 'http://foo.zz/', 'mentioned this in <a href="http://bar.com/mention">bar.com/mention</a>. <br /> <a href="http://bar.com/mention">via bar.com</a>') self.mox.ReplayAll() resp = self.get_response('http://bar.com/mention', 'http://foo.zz/post/1') self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/mention http://foo.zz/post/1') self.assertEquals('complete', bw.status) self.assertEquals(html, bw.html)
def test_success(self): html = """ <article class="h-entry"> <p class="p-author">my name</p> <p class="e-content"> i hereby reply <a class="u-in-reply-to" href="http://foo.com/post/1"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', 'i hereby reply\n<a class="u-in-reply-to" href="http://foo.com/post/1"></a>' ' <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) self.assertEquals({'id': 'fake id'}, json.loads(resp.body)) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals(self.source.key, bw.source) self.assertEquals('complete', bw.status) self.assertEquals('comment', bw.type) self.assertEquals(html, bw.html) self.assertEquals({'id': 'fake id'}, bw.published)
def test_u_url(self): html = """ <article class="h-entry"> <p class="p-name"></p> <!-- empty --> <p class="p-author">my name</p> <p class="e-content"> i hereby mention <a href="http://foo.com/post/1"></a> <a class="u-url" href="http://barzz.com/u/url"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', """mentioned this in <a href="http://barzz.com/u/url">barzz.com/u/url</a>. <br /> <a href="http://barzz.com/u/url">via barzz.com</a>""" ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status) self.assertEquals('post', bw.type) self.assertEquals('http://barzz.com/u/url', bw.u_url) self.assertEquals('http://barzz.com/u/url', bw.source_url())
def test_source_link_not_found(self): html = '<article class="h-entry"></article>' self.expect_requests_get('http://bar.com/reply', html) self.mox.ReplayAll() self.assert_error('Could not find target URL') bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status)
def test_rel_canonical_different_domain(self): self.expect_requests_get( 'http://foo.zz/post/1', """ <head> <link href='http://foo.com/post/1' rel='canonical'/> </head> foo bar""") html = """ <article class="h-entry"><p class="e-content"> <a href="http://bar.com/mention">this post</a> i hereby <a href="http://foo.zz/post/1">mention</a> </p></article>""" self.expect_requests_get('http://bar.com/mention', html) testutil.FakeSource.create_comment( 'http://foo.zz/post/1', 'foo.zz', 'http://foo.zz/', 'mentioned this in <a href="http://bar.com/mention">bar.com/mention</a>. <br /> <a href="http://bar.com/mention">via bar.com</a>' ) self.mox.ReplayAll() resp = self.get_response('http://bar.com/mention', 'http://foo.zz/post/1') self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/mention http://foo.zz/post/1') self.assertEquals('complete', bw.status) self.assertEquals(html, bw.html)
def test_source_missing_mf2(self): html = 'no microformats here, run along' self.expect_requests_get('http://bar.com/reply', html) self.mox.ReplayAll() self.assert_error('No microformats2 data found') bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(html, bw.html)
def test_create_comment_exception(self): self.expect_mention().AndRaise(exc.HTTPPaymentRequired()) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(402, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_source_link_not_found(self): html = '<article class="h-entry"></article>' self.expect_requests_get('http://bar.com/reply', html) self.mox.ReplayAll() self.assert_error('Could not find target URL') bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(html, bw.html)
def test_source_missing_mf2(self): html = 'no microformats here, run along' self.expect_requests_get('http://bar.com/reply', html) self.mox.ReplayAll() self.assert_error('No microformats2 data found') bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(html, bw.html)
def test_create_comment_404s(self): self.expect_mention().AndRaise(exc.HTTPNotFound('gone baby gone')) self.mox.ReplayAll() self.assert_error('gone baby gone', status=404) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_create_comment_exception(self): self.expect_mention().AndRaise(exceptions.NotAcceptable()) self.mox.ReplayAll() resp = self.post() self.assertEqual(406, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEqual('failed', bw.status) self.assertEqual(self.mention_html, bw.html)
def test_create_comment_404s(self): self.expect_mention().AndRaise(exc.HTTPNotFound('gone baby gone')) self.mox.ReplayAll() self.assert_error('gone baby gone', status=404) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_create_comment_exception(self): self.expect_mention().AndRaise(exc.HTTPPaymentRequired()) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(402, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_strip_utm_query_params(self): """utm_* query params should be stripped from target URLs.""" self.expect_mention() self.mox.ReplayAll() resp = self.get_response(target=urllib.quote( 'http://foo.com/post/1?utm_source=x&utm_medium=y')) self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_create_comment_401_disables_source(self): self.expect_mention().AndRaise(exc.HTTPUnauthorized('no way')) self.mox.ReplayAll() self.assert_error('no way', status=401) source = self.source.key.get() self.assertEquals('disabled', source.status) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_strip_utm_query_params(self): """utm_* query params should be stripped from target URLs.""" self.expect_mention() self.mox.ReplayAll() resp = self.post( target='http://foo.com/post/1?utm_source=x&utm_medium=y') self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEqual('complete', bw.status)
def test_strip_utm_query_params(self): """utm_* query params should be stripped from target URLs.""" self.expect_mention() self.mox.ReplayAll() resp = self.get_response(target=urllib.quote( 'http://foo.com/post/1?utm_source=x&utm_medium=y')) self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_repeated(self): # 1) first a failure self.expect_requests_get('http://bar.com/reply', '') # 2) should allow retrying, this one will succeed self.expect_requests_get( 'http://bar.com/reply', """ <article class="h-entry"> <a class="u-url" href="http://bar.com/reply"></a> <a class="u-repost-of" href="http://foo.com/post/1"></a> </article>""") testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'reposted this. <br /> <a href="http://bar.com/reply">via bar.com</a>' ) # 3) after success, another is a noop and returns 200 # TODO: check for "updates not supported" message self.mox.ReplayAll() # now the webmention requests. 1) failure self.assert_error('No microformats2 data found') bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) # 2) success resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status) self.assertEquals('repost', bw.type) # 3) noop repeated success # source without webmention feature resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_create_comment_401_disables_source(self): self.expect_mention().AndRaise(exc.HTTPUnauthorized('no way')) self.mox.ReplayAll() self.assert_error('no way', status=401) source = self.source.key.get() self.assertEquals('disabled', source.status) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(self.mention_html, bw.html)
def test_repeated(self): # 1) first a failure self.expect_requests_get('http://bar.com/reply', '') # 2) should allow retrying, this one will succeed self.expect_requests_get('http://bar.com/reply', """ <article class="h-entry"> <a class="u-url" href="http://bar.com/reply"></a> <a class="u-repost-of" href="http://foo.com/post/1"></a> </article>""") testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'reposted this. <br /> <a href="http://bar.com/reply">via bar.com</a>') # 3) after success, another is a noop and returns 200 # TODO: check for "updates not supported" message self.mox.ReplayAll() # now the webmention requests. 1) failure self.assert_error('No microformats2 data found') bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) # 2) success resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status) self.assertEquals('repost', bw.type) # 3) noop repeated success # source without webmention feature resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_source_link_check_ignores_fragment(self): html = """\ <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> <a href="http://foo.com/post/1"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>') self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_create_comment_exception(self): html = """\ <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> http://foo.com/post/1 </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', mox.IgnoreArg() ).AndRaise(exc.HTTPPaymentRequired()) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(402, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('failed', bw.status) self.assertEquals(html, bw.html)
def test_target_redirects(self): html = """\ <article class="h-entry"><p class="e-content"> http://second/ </p></article>""" redirects = ['http://second/', 'http://foo.com/final'] self.expect_requests_head('http://first/', redirected_url=redirects) self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/final', 'foo.com', 'http://foo.com/', mox.IgnoreArg()) self.mox.ReplayAll() resp = self.get_response(target='http://first/') self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/final') self.assertEquals('complete', bw.status) self.assertEquals(['http://first/', 'http://second/'], bw.redirected_target_urls)
def test_strip_utm_query_params(self): """utm_* query params should be stripped from target URLs.""" html = """\ <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> http://foo.com/post/1 </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>') self.mox.ReplayAll() resp = self.get_response(target=urllib.quote( 'http://foo.com/post/1?utm_source=x&utm_medium=y')) self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_source_link_check_ignores_fragment(self): html = """\ <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> <a href="http://foo.com/post/1"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>' ) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status)
def test_domain_translates_to_lowercase(self): html = """\ <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> X http://FoO.cOm/post/1 </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://FoO.cOm/post/1', 'foo.com', 'http://foo.com/', 'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>' ) self.mox.ReplayAll() resp = self.get_response(target='http://FoO.cOm/post/1') self.assertEqual(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://FoO.cOm/post/1') self.assertEqual('complete', bw.status)
def test_target_redirects(self): html = """\ <article class="h-entry"><p class="e-content"> http://second/ </p></article>""" redirects = ['http://second/', 'http://foo.com/final'] self.expect_requests_head('http://first/', redirected_url=redirects) self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment('http://foo.com/final', 'foo.com', 'http://foo.com/', mox.IgnoreArg()) self.mox.ReplayAll() resp = self.get_response(target='http://first/') self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/final') self.assertEquals('complete', bw.status) self.assertEquals(['http://first/', 'http://second/'], bw.redirected_target_urls)
def test_source_link_check_ignores_fragment(self): html = """\ <article class="h-entry"><p class="e-content"> <a href="http://bar.com/reply">(permalink)</a> <span class="p-name">my post</span> <a href="http://foo.com/post/1"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'foo.com', 'http://foo.com/', 'mentioned this in <a href="http://bar.com/reply">my post</a>. <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.post() self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEqual('complete', bw.status)
def test_target_redirects(self): html = """\ <article class="h-entry"><p class="e-content"> http://second/ </p></article>""" redirects = ['http://second/', 'http://foo.com/final'] self.expect_requests_head('http://first/', redirected_url=redirects) self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/final', 'foo.com', 'http://foo.com/', mox.IgnoreArg()).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.post(target='http://first/') self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/final') self.assertEqual('complete', bw.status) self.assertEqual(['http://first/', 'http://second/'], bw.redirected_target_urls)
def _test_success(self, html): self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', 'i hereby reply\n<a class="u-in-reply-to" href="http://foo.com/post/1"></a>' ' <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.post() self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) self.assertEqual({'id': 'fake id'}, resp.json) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEqual(self.source.key, bw.source) self.assertEqual('complete', bw.status) self.assertEqual('comment', bw.type) self.assertEqual(html, bw.html) self.assertEqual({'id': 'fake id'}, bw.published)
def test_unicode_in_target_and_source_urls(self): """Unicode chars in target and source URLs should work.""" # note the … and ✁ chars target = u'http://foo.com/2014/11/23/england-german…iendly-wembley' source = u'http://bar.com/✁/1' html = u"""\ <meta charset="utf-8"> <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> %s </p></article>""" % target self.expect_requests_get(source, html) comment = u'mentioned this in <a href="%s">my post</a>. <br /> <a href="%s">via bar.com</a>' % (source, source) testutil.FakeSource.create_comment(target, 'foo.com', 'http://foo.com/', comment) self.mox.ReplayAll() resp = self.get_response(source=source, target=target) self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id(' '.join((source, target))) self.assertEquals('complete', bw.status)
def test_reply_outside_e_content(self): html = """ <article class="h-entry"> <p class="p-author">my name</p> <p class="p-in-reply-to h-cite"><a href="http://foo.com/post/1"></a></p> <div class="e-content"> i hereby reply </div></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', 'i hereby reply <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status) self.assertEquals({'id': 'fake id'}, bw.published)
def test_reply_outside_e_content(self): html = """ <article class="h-entry"> <p class="p-author">my name</p> <p class="p-in-reply-to h-cite"><a href="http://foo.com/post/1"></a></p> <div class="e-content"> i hereby reply </div></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', 'i hereby reply <br /> <a href="http://bar.com/reply">via bar.com</a>' ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.post() self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id( 'http://bar.com/reply http://foo.com/post/1') self.assertEqual('complete', bw.status) self.assertEqual({'id': 'fake id'}, bw.published) self.assertEqual(html, bw.html)
def test_unicode_in_target_and_source_urls(self): """Unicode chars in target and source URLs should work.""" # note the … and ✁ chars target = 'http://foo.com/2014/11/23/england-german…iendly-wembley' source = 'http://bar.com/✁/1' html = f""" <meta charset="utf-8"> <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> {target} </p></article>""" self.expect_requests_get(source, html) comment = f'mentioned this in <a href="{source}">my post</a>. <br /> <a href="{source}">via bar.com</a>' testutil.FakeSource.create_comment( target, 'foo.com', 'http://foo.com/', comment).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.post(source=source, target=target) self.assertEqual(200, resp.status_code, resp.get_data(as_text=True)) bw = BlogWebmention.get_by_id(' '.join((source, target))) self.assertEqual('complete', bw.status)
def test_u_url(self): html = """ <article class="h-entry"> <p class="p-name"></p> <!-- empty --> <p class="p-author">my name</p> <p class="e-content"> i hereby mention <a href="http://foo.com/post/1"></a> <a class="u-url" href="http://barzz.com/u/url"></a> </p></article>""" self.expect_requests_get('http://bar.com/reply', html) testutil.FakeSource.create_comment( 'http://foo.com/post/1', 'my name', 'http://foo.com/', """mentioned this in <a href="http://barzz.com/u/url">barzz.com/u/url</a>. <br /> <a href="http://barzz.com/u/url">via barzz.com</a>""" ).AndReturn({'id': 'fake id'}) self.mox.ReplayAll() resp = self.get_response() self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id('http://bar.com/reply http://foo.com/post/1') self.assertEquals('complete', bw.status) self.assertEquals('post', bw.type) self.assertEquals('http://barzz.com/u/url', bw.u_url) self.assertEquals('http://barzz.com/u/url', bw.source_url())
def test_unicode_in_target_and_source_urls(self): """Unicode chars in target and source URLs should work.""" # note the … and ✁ chars target = 'http://foo.com/2014/11/23/england-german…iendly-wembley' source = 'http://bar.com/✁/1' html = u"""\ <meta charset="utf-8"> <article class="h-entry"><p class="e-content"> <span class="p-name">my post</span> %s </p></article>""" % target self.expect_requests_get(source, html) comment = 'mentioned this in <a href="%s">my post</a>. <br /> <a href="%s">via bar.com</a>' % ( source, source) testutil.FakeSource.create_comment(target, 'foo.com', 'http://foo.com/', comment) self.mox.ReplayAll() resp = self.get_response(source=source, target=target) self.assertEquals(200, resp.status_int, resp.body) bw = BlogWebmention.get_by_id(' '.join((source, target))) self.assertEquals('complete', bw.status)