kopia lustrzana https://gitlab.com/jaywink/federation
Fix Mastodon parser if version has non-numbers
rodzic
7a328459ba
commit
8111f2d4e4
|
@ -60,7 +60,8 @@ def parse_mastodon_document(doc, host):
|
|||
# TODO parse about page
|
||||
# https://github.com/TheKinrar/mastodon-instances/blob/master/tasks/update_instances.js#L508
|
||||
# result['open_signups']
|
||||
version = [int(part) for part in doc.get('version', '').split('.')]
|
||||
version = re.sub(r'[^0-9.]', '', doc.get('version', ''))
|
||||
version = [int(part) for part in version.split('.')]
|
||||
if version >= [1, 6, 0]:
|
||||
result['protocols'] = ['ostatus', 'activitypub']
|
||||
else:
|
||||
|
|
|
@ -17,6 +17,25 @@ MASTODON_DOC = """
|
|||
"fields": []}}
|
||||
"""
|
||||
|
||||
MASTODON_RC_DOC = """
|
||||
{"uri": "mastodon.local", "title": "Mastodon",
|
||||
"description": "This page describes the mastodon.local",
|
||||
"email": "hello@mastodon.local", "version": "2.4.1rc1", "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": {"id": "1", "username": "Admin", "acct": "Admin", "display_name": "Admin dude", "locked": false,
|
||||
"bot": false, "created_at": "2016-03-16T14:34:26.392Z",
|
||||
"note": "\u003cp\u003eSuperuser\u003c/p\u003e",
|
||||
"url": "https://mastodon.local/@Admin",
|
||||
"avatar": "https://files.mastodon.local/accounts/avatars/000/000/001/original/file.png",
|
||||
"avatar_static": "https://files.mastodon.local/accounts/avatars/000/000/001/original/file.png",
|
||||
"header": "https://files.mastodon.local/accounts/headers/000/000/001/original/file.jpeg",
|
||||
"header_static": "https://files.mastodon.local/accounts/headers/000/000/001/original/file.jpeg",
|
||||
"followers_count": 81779, "following_count": 506, "statuses_count": 36722, "emojis": [],
|
||||
"fields": []}}
|
||||
"""
|
||||
|
||||
MASTODON_ACTIVITY_DOC = """
|
||||
[
|
||||
{"week":"1526860800","statuses":"121188","logins":"8779","registrations":"1143"},
|
||||
|
|
|
@ -5,7 +5,8 @@ from federation.hostmeta.parsers import (
|
|||
parse_nodeinfo_document, parse_nodeinfo2_document, parse_statisticsjson_document, int_or_none,
|
||||
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)
|
||||
NODEINFO2_10_DOC, NODEINFO_10_DOC, NODEINFO_20_DOC, STATISTICS_JSON_DOC, MASTODON_DOC, MASTODON_ACTIVITY_DOC,
|
||||
MASTODON_RC_DOC)
|
||||
|
||||
|
||||
class TestIntOrNone:
|
||||
|
@ -46,6 +47,38 @@ class TestParseMastodonDocument:
|
|||
},
|
||||
}
|
||||
|
||||
@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
|
||||
result = parse_mastodon_document(json.loads(MASTODON_RC_DOC), 'example.com')
|
||||
assert result == {
|
||||
'organization': {
|
||||
'account': 'https://mastodon.local/@Admin',
|
||||
'contact': 'hello@mastodon.local',
|
||||
'name': 'Admin dude',
|
||||
},
|
||||
'host': 'example.com',
|
||||
'name': 'Mastodon',
|
||||
'open_signups': False,
|
||||
'protocols': ["ostatus", "activitypub"],
|
||||
'relay': False,
|
||||
'server_meta': {},
|
||||
'services': [],
|
||||
'platform': 'mastodon',
|
||||
'version': '2.4.1rc1',
|
||||
'features': {},
|
||||
'activity': {
|
||||
'users': {
|
||||
'total': 159726,
|
||||
'half_year': 90774,
|
||||
'monthly': 27829,
|
||||
'weekly': 8779,
|
||||
},
|
||||
'local_posts': None,
|
||||
'local_comments': None,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class TestParseNodeInfoDocument:
|
||||
def test_parse_nodeinfo_10_document(self):
|
||||
|
|
Ładowanie…
Reference in New Issue