Where an identifier of a remote object is called "url", rename it to "remote_url".

We were calling it "url" in some places and "remote_url" in others.
status-serialisers
Marnanel Thurman 2020-10-19 16:17:58 +01:00
rodzic d2fda1e974
commit bb67a18112
1 zmienionych plików z 29 dodań i 29 usunięć

Wyświetl plik

@ -46,7 +46,7 @@ class DummyMessage(object):
return 'test message' return 'test message'
def mock_remote_object( def mock_remote_object(
url, remote_url,
content = '', content = '',
status = 200, status = 200,
as_post = False, as_post = False,
@ -67,15 +67,15 @@ def mock_remote_object(
else: else:
method = httpretty.GET method = httpretty.GET
def return_body(request, url, stuff): def return_body(request, remote_url, stuff):
logger.info('%s: fetched', url) logger.info('%s: fetched', remote_url)
if on_fetch is not None: if on_fetch is not None:
on_fetch() on_fetch()
return status, stuff, body return status, stuff, body
httpretty.register_uri( httpretty.register_uri(
method, method,
url, remote_url,
status=status, status=status,
headers=headers, headers=headers,
body = return_body, body = return_body,
@ -83,12 +83,12 @@ def mock_remote_object(
) )
logger.debug('Mocking %s as %d: %s', logger.debug('Mocking %s as %d: %s',
url, remote_url,
status, status,
content) content)
def create_remote_person( def create_remote_person(
url, remote_url,
name, name,
on_fetch = None, on_fetch = None,
auto_fetch = False, auto_fetch = False,
@ -99,7 +99,7 @@ def create_remote_person(
Mock a remote user. Mock a remote user.
Parameters: Parameters:
url: the URL representing this user remote_url: the URL representing this user
name: the user's name (their "preferredUsername") name: the user's name (their "preferredUsername")
on_fetch: an optional callback for when someone on_fetch: an optional callback for when someone
fetches the user's details fetches the user's details
@ -126,13 +126,13 @@ def create_remote_person(
body = as_json( body = as_json(
remote_user( remote_user(
url=url, remote_url=remote_url,
name=name, name=name,
**fields, **fields,
)) ))
mock_remote_object( mock_remote_object(
url=url, remote_url=remote_url,
on_fetch=on_fetch, on_fetch=on_fetch,
content=body, content=body,
) )
@ -140,13 +140,13 @@ def create_remote_person(
if auto_fetch: if auto_fetch:
from kepi.sombrero_sendpub.fetch import fetch from kepi.sombrero_sendpub.fetch import fetch
return fetch(url, return fetch(remote_url,
expected_type=trilby_models.RemotePerson) expected_type=trilby_models.RemotePerson)
else: else:
return None return None
def create_remote_collection( def create_remote_collection(
url, remote_url,
items, items,
number_per_page = 10, number_per_page = 10,
): ):
@ -154,13 +154,13 @@ def create_remote_collection(
PAGE_URL_FORMAT = '%s?page=%d' PAGE_URL_FORMAT = '%s?page=%d'
mock_remote_object( mock_remote_object(
url=url, remote_url=remote_url,
content=as_json({ content=as_json({
"@context" : "https://www.w3.org/ns/activitystreams", "@context" : "https://www.w3.org/ns/activitystreams",
"id" : url, "id" : remote_url,
"type" : "OrderedCollection", "type" : "OrderedCollection",
"totalItems" : len(items), "totalItems" : len(items),
"first" : PAGE_URL_FORMAT % (url, 1), "first" : PAGE_URL_FORMAT % (remote_url, 1),
}), }),
) )
@ -169,21 +169,21 @@ def create_remote_collection(
fields = { fields = {
"@context" : CONTEXT_URL, "@context" : CONTEXT_URL,
"id" : PAGE_URL_FORMAT % (url, i), "id" : PAGE_URL_FORMAT % (remote_url, i),
"type" : "OrderedCollectionPage", "type" : "OrderedCollectionPage",
"totalItems" : len(items), "totalItems" : len(items),
"partOf": url, "partOf": remote_url,
"orderedItems": items[(i-1)*number_per_page:i*number_per_page], "orderedItems": items[(i-1)*number_per_page:i*number_per_page],
} }
if i>1: if i>1:
fields['prev'] = PAGE_URL_FORMAT % (url, i-1) fields['prev'] = PAGE_URL_FORMAT % (remote_url, i-1)
if i<page_count+1: if i<page_count+1:
fields['next'] = PAGE_URL_FORMAT % (url, i+1) fields['next'] = PAGE_URL_FORMAT % (remote_url, i+1)
mock_remote_object( mock_remote_object(
url = PAGE_URL_FORMAT % (url, i), remote_url = PAGE_URL_FORMAT % (remote_url, i),
content=as_json(fields), content=as_json(fields),
) )
@ -298,24 +298,24 @@ def post_test_message(
return response return response
def remote_user(url, name, def remote_user(remote_url, name,
publicKey='', publicKey='',
sharedInbox=None, sharedInbox=None,
): ):
result = { result = {
'@context': CONTEXT_URL, '@context': CONTEXT_URL,
'id': url, 'id': remote_url,
'type': 'Person', 'type': 'Person',
'following': url+"/following", 'following': remote_url+"/following",
'followers': url+"/followers", 'followers': remote_url+"/followers",
'inbox': url+"/inbox", 'inbox': remote_url+"/inbox",
'outbox': url+"/outbox", 'outbox': remote_url+"/outbox",
'featured': url+"/collections/featured", 'featured': remote_url+"/collections/featured",
'preferredUsername': name, 'preferredUsername': name,
'url': url, 'url': remote_url,
'publicKey': { 'publicKey': {
'id': url+'#main-key', 'id': remote_url+'#main-key',
'owner': url, 'owner': remote_url,
'publicKeyPem': publicKey, 'publicKeyPem': publicKey,
}, },
} }