Пример #1
0
    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)
Пример #2
0
  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)
Пример #3
0
  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)
Пример #4
0
    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())
Пример #5
0
 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)
Пример #6
0
    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)
Пример #7
0
 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)
Пример #8
0
  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)
Пример #9
0
 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)
Пример #10
0
 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)
Пример #11
0
  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)
Пример #12
0
    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)
Пример #13
0
    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)
Пример #14
0
    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)
Пример #15
0
  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)
Пример #16
0
  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)
Пример #17
0
    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)
Пример #18
0
    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)
Пример #19
0
    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)
Пример #20
0
    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)
Пример #21
0
  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)
Пример #22
0
  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)
Пример #23
0
  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)
Пример #24
0
  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)
Пример #25
0
  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)
Пример #26
0
    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)
Пример #27
0
    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)
Пример #28
0
    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)
Пример #29
0
    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)
Пример #30
0
    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)
Пример #31
0
    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)
Пример #32
0
  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)
Пример #33
0
  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)
Пример #34
0
    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)
Пример #35
0
    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)
Пример #36
0
  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())
Пример #37
0
    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)