Format mastodon output
This commit is contained in:
@@ -6,7 +6,7 @@ import threading
|
||||
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
||||
from urllib.parse import parse_qs
|
||||
from uuid import uuid4
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
@@ -445,13 +445,34 @@ def test_link_submission_posts_to_enabled_mastodon_plugin():
|
||||
assert received['path'] == '/api/v1/statuses'
|
||||
assert received['authorization'] == 'Bearer test-token'
|
||||
assert received['content_type'] == 'application/x-www-form-urlencoded'
|
||||
assert received['body'] == {'status': ['A useful page\nWorth sharing\nFrom my #LinkLog: https://example.com/useful #python #web']}
|
||||
assert received['body'] == {'status': ['From my #LinkLog: A useful page\n\nWorth sharing\n\nfrom: https://example.com/useful\n\n#python #web']}
|
||||
finally:
|
||||
server.shutdown()
|
||||
thread.join()
|
||||
server.server_close()
|
||||
|
||||
|
||||
def test_mastodon_post_without_title_omits_source_line():
|
||||
from backend.app.services.plugin_manager import MastodonPlugin
|
||||
|
||||
response = MagicMock()
|
||||
response.__enter__.return_value.read.return_value = b'{"id":"status-2"}'
|
||||
plugin = MastodonPlugin()
|
||||
plugin.initialize({'instance': 'https://mastodon.example', 'access_token': 'test-token'})
|
||||
|
||||
with patch('backend.app.services.plugin_manager.urlopen', return_value=response) as open_url:
|
||||
result = plugin.handle_event({
|
||||
'url': 'https://example.com/useful',
|
||||
'title': '',
|
||||
'comment': 'A comment',
|
||||
'tags': ['#tag'],
|
||||
})
|
||||
|
||||
body = parse_qs(open_url.call_args.args[0].data.decode())['status'][0]
|
||||
assert result['status'] == 'posted'
|
||||
assert body == 'From my #LinkLog:\n\nA comment\n\n#tag'
|
||||
|
||||
|
||||
def test_plugin_config_can_be_saved_for_mastodon():
|
||||
headers = login_headers()
|
||||
assert client.put('/api/user/plugins/mastodon', headers=headers, json={
|
||||
|
||||
Reference in New Issue
Block a user