kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
435389d0b9
commit
002c6a9740
16
protocol.py
16
protocol.py
|
@ -1,6 +1,7 @@
|
|||
"""Base protocol class and common code."""
|
||||
import logging
|
||||
import threading
|
||||
from urllib.parse import urljoin
|
||||
|
||||
from cachetools import cached, LRUCache
|
||||
from flask import g, request
|
||||
|
@ -106,6 +107,21 @@ class Protocol:
|
|||
label = domain.removesuffix(common.SUPERDOMAIN)
|
||||
return PROTOCOLS.get(label)
|
||||
|
||||
@classmethod
|
||||
def subdomain_url(cls, path=None):
|
||||
"""Returns the URL for a given path on this protocol's subdomain.
|
||||
|
||||
Eg for the path 'foo/bar' on ActivityPub, returns
|
||||
'https://ap.brid.gy/foo/bar'.
|
||||
|
||||
Args:
|
||||
path: str
|
||||
|
||||
Returns:
|
||||
str, URL
|
||||
"""
|
||||
return urljoin(f'https://{cls.ABBREV or "fed"}{common.SUPERDOMAIN}/', path)
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
"""Returns whether this protocol owns the id, or None if it's unclear.
|
||||
|
|
|
@ -78,6 +78,11 @@ class ProtocolTest(TestCase):
|
|||
with app.test_request_context('/foo', base_url=url):
|
||||
self.assertEqual(expected, Protocol.for_request(fed=Fake))
|
||||
|
||||
def test_subdomain_url(self):
|
||||
self.assertEqual('https://fa.brid.gy/', Fake.subdomain_url())
|
||||
self.assertEqual('https://fa.brid.gy/foo?bar', Fake.subdomain_url('foo?bar'))
|
||||
self.assertEqual('https://fed.brid.gy/', UIProtocol.subdomain_url())
|
||||
|
||||
@patch('requests.get')
|
||||
def test_receive_reply_not_feed_not_notification(self, mock_get):
|
||||
Follower.get_or_create(to=Fake.get_or_create(id=ACTOR['id']),
|
||||
|
|
Ładowanie…
Reference in New Issue