def test_process_wm(db, client, target_url, mocker): source_url = 'http://foreign/permalink/url' urlopen = mocker.patch('urllib.request.urlopen') getter = mocker.patch('requests.get') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects getter.return_value = FakeResponse(""" <!DOCTYPE html> <html> <head></head> <body class="h-entry"> <a href="{}" class="u-in-reply-to">In Reply To</a> This is the source of the webmention <a href="{}" class="u-url">Permalink</a> </body> </html> """.format(target_url, source_url)) assert not current_user.is_authenticated() result = wm_receiver.interpret_mention(source_url, target_url) assert result.post.permalink == target_url assert result.mentions assert result.mentions[0].reftype == 'reply' assert result.mention_results[0].create assert not result.delete assert not result.error getter.assert_called_once_with('http://foreign/permalink/url', timeout=TIMEOUT, headers=HEADERS)
def test_process_wm(db, client, target_url, mocker): source_url = 'http://foreign/permalink/url' urlopen = mocker.patch('urllib.request.urlopen') getter = mocker.patch('requests.get') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects getter.return_value = FakeResponse(""" <!DOCTYPE html> <html> <head></head> <body class="h-entry"> <a href="{}" class="u-in-reply-to">In Reply To</a> This is the source of the webmention <a href="{}" class="u-url">Permalink</a> </body> </html> """.format(target_url, source_url)) assert not current_user result = wm_receiver.interpret_mention(source_url, target_url) assert result.post.permalink == target_url assert result.mentions assert result.mentions[0].reftype == 'reply' assert result.mention_results[0].create assert not result.delete assert not result.error getter.assert_called_once_with('http://foreign/permalink/url', timeout=TIMEOUT, headers=HEADERS)
def test_process_wm_no_target_post(client, mocker): source_url = 'http://foreign/permalink/url' target_url = 'http://example.com/buy/cialis' # possible spam urlopen = mocker.patch('urllib.request.urlopen') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects assert not current_user.is_authenticated() result = wm_receiver.interpret_mention(source_url, target_url) assert result.post is None assert not result.mentions assert not result.delete assert result.error.startswith('Webmention could not find target')
def test_process_wm_no_target_post(client, mocker): source_url = 'http://foreign/permalink/url' target_url = 'http://example.com/buy/cialis' # possible spam urlopen = mocker.patch('urllib.request.urlopen') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects assert not current_user result = wm_receiver.interpret_mention(source_url, target_url) assert result.post is None assert not result.mentions assert not result.delete assert result.error.startswith('Webmention could not find target')
def test_process_wm_deleted(client, target_url, mocker): source_url = 'http://foreign/permalink/url' urlopen = mocker.patch('urllib.request.urlopen') getter = mocker.patch('requests.get') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects getter.return_value = FakeResponse(status_code=410) assert not current_user.is_authenticated() result = wm_receiver.interpret_mention(source_url, target_url) assert result.post.permalink == target_url assert not result.mentions assert result.delete is True assert result.error is None getter.assert_called_once_with('http://foreign/permalink/url', timeout=TIMEOUT, headers=HEADERS)
def test_process_wm_deleted(client, target_url, mocker): source_url = 'http://foreign/permalink/url' urlopen = mocker.patch('urllib.request.urlopen') getter = mocker.patch('requests.get') urlopen.return_value = FakeUrlOpen(target_url) # follows redirects getter.return_value = FakeResponse(status_code=410) assert not current_user result = wm_receiver.interpret_mention(source_url, target_url) assert result.post.permalink == target_url assert not result.mentions assert result.delete is True assert result.error is None getter.assert_called_once_with('http://foreign/permalink/url', timeout=TIMEOUT, headers=HEADERS)