kopia lustrzana https://github.com/tsileo/little-boxes
More test case
rodzic
c842c282e5
commit
f2fa730da7
|
@ -9,6 +9,7 @@ from enum import Enum
|
|||
from .errors import BadActivityError
|
||||
from .errors import UnexpectedActivityTypeError
|
||||
from .errors import NotFromOutboxError
|
||||
|
||||
# from .errors import ActivityNotFoundError
|
||||
# from .urlutils import check_url
|
||||
from .utils import parse_collection
|
||||
|
@ -190,6 +191,7 @@ class BaseBackend(object):
|
|||
summary="Hello",
|
||||
id=f"https://lol.com/{pusername}",
|
||||
inbox=f"https://lol.com/{pusername}/inbox",
|
||||
followers=f"https://lol.com/{pusername}/followers",
|
||||
)
|
||||
|
||||
self.USERS[p.preferredUsername] = p
|
||||
|
@ -203,6 +205,14 @@ class BaseBackend(object):
|
|||
return p
|
||||
|
||||
def fetch_iri(self, iri: str):
|
||||
if iri.endswith("/followers"):
|
||||
data = self.FOLLOWERS[iri.replace("/followers", "")]
|
||||
return {
|
||||
"id": iri,
|
||||
"type": ActivityType.ORDERED_COLLECTION.value,
|
||||
"totalItems": len(data),
|
||||
"orderedItems": data,
|
||||
}
|
||||
return self.FETCH_MOCK[iri]
|
||||
|
||||
def get_user(self, username: str) -> "Person":
|
||||
|
@ -381,7 +391,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
|||
actor = self._validate_person(actor)
|
||||
self._data["actor"] = actor
|
||||
elif self.ACTIVITY_TYPE == ActivityType.NOTE:
|
||||
if 'attributedTo' not in kwargs:
|
||||
if "attributedTo" not in kwargs:
|
||||
raise BadActivityError(f"Note is missing attributedTo")
|
||||
else:
|
||||
raise BadActivityError("missing actor")
|
||||
|
@ -686,7 +696,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
|||
ActivityType.COLLECTION.value,
|
||||
ActivityType.ORDERED_COLLECTION.value,
|
||||
]:
|
||||
for item in parse_collection(raw_actor):
|
||||
for item in parse_collection(raw_actor, fetcher=BACKEND.fetch_iri):
|
||||
if item in [actor_id, AS_PUBLIC]:
|
||||
continue
|
||||
try:
|
||||
|
|
|
@ -253,3 +253,62 @@ def test_little_boxes_follow_and_new_note_to_single_actor():
|
|||
lambda create: _assert_eq(create.get_object().id, note.id),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def test_little_boxes_follow_and_new_note_to_followers():
|
||||
back, f = test_little_boxes_follow()
|
||||
|
||||
me = back.get_user("tom")
|
||||
other = back.get_user("tom2")
|
||||
|
||||
outbox = ap.Outbox(me)
|
||||
|
||||
note = ap.Note(
|
||||
to=[me.followers], cc=[other.id], attributedTo=me.id, content="Hello"
|
||||
)
|
||||
outbox.post(note)
|
||||
|
||||
back.assert_called_methods(
|
||||
me,
|
||||
(
|
||||
"an Create activity is published",
|
||||
"outbox_new",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda activity: _assert_eq(activity.get_object().id, note.id),
|
||||
),
|
||||
(
|
||||
'"outbox_create" hook is called',
|
||||
"outbox_create",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda create: _assert_eq(create.get_object().id, note.id),
|
||||
),
|
||||
(
|
||||
"the Undo activity is posted to the followee",
|
||||
"post_to_remote_inbox",
|
||||
lambda as_actor: _assert_eq(as_actor.id, me.id),
|
||||
lambda payload: None,
|
||||
lambda recipient: _assert_eq(recipient, other.inbox),
|
||||
),
|
||||
)
|
||||
|
||||
back.assert_called_methods(
|
||||
other,
|
||||
(
|
||||
"receiving the Undo, ensure we check the actor is not blocked",
|
||||
"outbox_is_blocked",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda remote_actor: _assert_eq(remote_actor, me.id),
|
||||
),
|
||||
(
|
||||
"receiving the Create activity",
|
||||
"inbox_new",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda activity: _assert_eq(activity.get_object().id, note.id),
|
||||
),
|
||||
(
|
||||
'"inbox_create" hook is called',
|
||||
"inbox_create",
|
||||
lambda as_actor: _assert_eq(as_actor.id, other.id),
|
||||
lambda create: _assert_eq(create.get_object().id, note.id),
|
||||
),
|
||||
)
|
||||
|
|
Ładowanie…
Reference in New Issue