kopia lustrzana https://gitlab.com/jaywink/federation
Merge branch 'metainfo-parser-fixees' into 'master'
Metainfo parser fixes Closes #122 See merge request jaywink/federation!135merge-requests/136/head
commit
ddfb82fb88
|
@ -71,9 +71,13 @@ def parse_mastodon_document(doc, host):
|
|||
# TODO figure out what to do with posts vs comments vs statuses
|
||||
#result['activity']['users']['local_posts'] = int_or_none(doc.get('stats', {}).get('status_count'))
|
||||
|
||||
result['organization']['account'] = doc.get('contact_account', {}).get('url', '')
|
||||
if "contact_account" in doc and doc.get('contact_account') is not None:
|
||||
contact_account = doc.get('contact_account', {})
|
||||
else:
|
||||
contact_account = {}
|
||||
result['organization']['account'] = contact_account.get('url', '')
|
||||
result['organization']['contact'] = doc.get('email', '')
|
||||
result['organization']['name'] = doc.get('contact_account', {}).get('display_name', '')
|
||||
result['organization']['name'] = contact_account.get('display_name', '')
|
||||
|
||||
activity_doc, _status_code, _error = fetch_document(host=host, path='/api/v1/instance/activity')
|
||||
if activity_doc:
|
||||
|
@ -143,7 +147,7 @@ def parse_nodeinfo2_document(doc, host):
|
|||
result['platform'] = doc.get('server', {}).get('software', 'unknown').lower()
|
||||
result['version'] = doc.get('server', {}).get('version', '') or ''
|
||||
# Ensure baseUrl is reported as the host we called
|
||||
base_url = doc.get('server', {}).get('baseUrl', '')
|
||||
base_url = doc.get('server', {}).get('baseUrl', '').rstrip('/')
|
||||
cleaned_base_url = re.sub(r'https?://', '', base_url)
|
||||
if cleaned_base_url.startswith(host):
|
||||
result['host'] = cleaned_base_url
|
||||
|
|
|
@ -17,6 +17,16 @@ MASTODON_DOC = """
|
|||
"fields": []}}
|
||||
"""
|
||||
|
||||
MASTODON_DOC_NULL_CONTACT = """
|
||||
{"uri": "mastodon.local", "title": "Mastodon",
|
||||
"description": "This page describes the mastodon.local",
|
||||
"email": "", "version": "2.4.0", "urls": {"streaming_api": "wss://mastodon.local"},
|
||||
"stats": {"user_count": 159726, "status_count": 6059606, "domain_count": 4703},
|
||||
"thumbnail": "https://files.mastodon.local/site_uploads/files/000/000/001/original/file.jpeg",
|
||||
"languages": ["en"],
|
||||
"contact_account": null}
|
||||
"""
|
||||
|
||||
MASTODON_RC_DOC = """
|
||||
{"uri": "mastodon.local", "title": "Mastodon",
|
||||
"description": "This page describes the mastodon.local",
|
||||
|
@ -69,7 +79,7 @@ NODEINFO2_10_DOC = """
|
|||
{
|
||||
"version": "1.0",
|
||||
"server": {
|
||||
"baseUrl": "https://example.com",
|
||||
"baseUrl": "https://example.com/",
|
||||
"name": "Example server",
|
||||
"software": "example",
|
||||
"version": "0.5.0"
|
||||
|
|
|
@ -6,7 +6,7 @@ from federation.hostmeta.parsers import (
|
|||
parse_mastodon_document)
|
||||
from federation.tests.fixtures.hostmeta import (
|
||||
NODEINFO2_10_DOC, NODEINFO_10_DOC, NODEINFO_20_DOC, STATISTICS_JSON_DOC, MASTODON_DOC, MASTODON_ACTIVITY_DOC,
|
||||
MASTODON_RC_DOC)
|
||||
MASTODON_RC_DOC, MASTODON_DOC_NULL_CONTACT)
|
||||
|
||||
|
||||
class TestIntOrNone:
|
||||
|
@ -47,6 +47,38 @@ class TestParseMastodonDocument:
|
|||
},
|
||||
}
|
||||
|
||||
@patch('federation.hostmeta.parsers.fetch_document')
|
||||
def test_parse_mastodon_document__null_contact_account(self, mock_fetch):
|
||||
mock_fetch.return_value = MASTODON_ACTIVITY_DOC, 200, None
|
||||
result = parse_mastodon_document(json.loads(MASTODON_DOC_NULL_CONTACT), 'example.com')
|
||||
assert result == {
|
||||
'organization': {
|
||||
'account': '',
|
||||
'contact': '',
|
||||
'name': '',
|
||||
},
|
||||
'host': 'example.com',
|
||||
'name': 'Mastodon',
|
||||
'open_signups': False,
|
||||
'protocols': ["ostatus", "activitypub"],
|
||||
'relay': False,
|
||||
'server_meta': {},
|
||||
'services': [],
|
||||
'platform': 'mastodon',
|
||||
'version': '2.4.0',
|
||||
'features': {},
|
||||
'activity': {
|
||||
'users': {
|
||||
'total': 159726,
|
||||
'half_year': 90774,
|
||||
'monthly': 27829,
|
||||
'weekly': 8779,
|
||||
},
|
||||
'local_posts': None,
|
||||
'local_comments': None,
|
||||
},
|
||||
}
|
||||
|
||||
@patch('federation.hostmeta.parsers.fetch_document')
|
||||
def test_parse_mastodon_document__rc_version(self, mock_fetch):
|
||||
mock_fetch.return_value = MASTODON_ACTIVITY_DOC, 200, None
|
||||
|
|
Ładowanie…
Reference in New Issue