Skip to content

Commit

Permalink
Reply test, closes #148 (#157)
Browse files Browse the repository at this point in the history
Co-authored-by: Johannes Ernst <git@j12t.org>
  • Loading branch information
jernst and Johannes Ernst authored Oct 1, 2024
1 parent 81a1ff4 commit 9f9edb6
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 10 deletions.
86 changes: 76 additions & 10 deletions tests/fediverse/for0.4/announce.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,76 @@
# https://github.com/fediverse-devnet/feditest-tests-fediverse/issues/150
#
# Can this be done meaningfully with two Actors instead of three
#
# Three nodes
# A follows B
# C creates Note X
# B accesses X
# B announces X
# A receives the announcement
"""
Tests that a note by actor A can be announced by an actor B on a different Fediverse Node
and the announce is seen by actor C that is following B.
To not complicate constellation setup and stay with two Nodes, we have actors A and C on the same Node.
"""

from datetime import datetime

from feditest import AssertionFailure, InteropLevel, SpecLevel, assert_that, step, test
from feditest.protocols.fediverse import FediverseNode

@test
class AnnounceTest:
def __init__(self,
node1: FediverseNode,
node2: FediverseNode
) -> None:
self.node1 = node1
self.node1_poster_actor_uri = None
self.node1_follower_actor_uri = None

self.node2 = node2
self.node2_announcer_actor_uri = None

self.note_uri = None
self.note_content = f'Testing announce {datetime.now()}'


@step
def provision_actors(self):
self.node1_poster_actor_uri = self.node1.obtain_actor_document_uri('poster')
assert self.node1_poster_actor_uri
print( f'XXX poster: { self.node1_poster_actor_uri }')

self.node2_announcer_actor_uri = self.node2.obtain_actor_document_uri('announcer')
assert self.node2_announcer_actor_uri
print( f'XXX announcer: { self.node2_announcer_actor_uri }')

self.node1_follower_actor_uri = self.node1.obtain_actor_document_uri('follower')
assert self.node1_follower_actor_uri
print( f'XXX follower: { self.node1_follower_actor_uri }')


@step
def follow(self):
self.node1.make_follow(self.node1_follower_actor_uri, self.node2_announcer_actor_uri)
self.node2.wait_until_actor_is_followed_by_actor(self.node2_announcer_actor_uri, self.node1_follower_actor_uri)
self.node1.wait_until_actor_is_following_actor(self.node1_follower_actor_uri, self.node2_announcer_actor_uri)


@step
def poster_creates_note(self):
self.note_uri = self.node1.make_create_note(self.node1_poster_actor_uri, self.note_content)
assert self.note_uri # We expect that this works: tests the node1 Node implementation


@step
def booster_boosts(self):
# This may throw an exception if node2 could not find the note
self.node2.make_announce(self.node2_announcer_actor_uri, self.note_uri)


@step
def wait_until_boost_received_by_follower(self):
try:
received_content = self.node1.wait_until_actor_has_received_note(self.node1_follower_actor_uri, self.note_uri)

except TimeoutError as e:
raise AssertionFailure(SpecLevel.MUST, InteropLevel.PROBLEM, e)

if self.note_content not in received_content:
raise AssertionFailure(SpecLevel.MUST, InteropLevel.PROBLEM, f'Received anounce does not contain payload: "{ received_content }".')

if self.note_content != received_content:
raise AssertionFailure(SpecLevel.IMPLIED, InteropLevel.DEGRADED, f'Received announce modified from original: "{ received_content }".')
57 changes: 57 additions & 0 deletions tests/fediverse/for0.4/like.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,60 @@
# A receives the like
# B undoes the Like
# On A the post is not Liked any more


"""
Tests that a note by actor A can be Liked by an actor B on a different Fediverse Node
and both see the Like.
"""

from datetime import datetime

from feditest import AssertionFailure, InteropLevel, SpecLevel, step, test
from feditest.protocols import TimeoutException
from feditest.protocols.fediverse import FediverseNode

@test
class LikeTest:
def __init__(self,
leader_node: FediverseNode,
follower_node: FediverseNode
) -> None:
self.leader_node = leader_node
self.leader_actor_uri = None

self.follower_node = follower_node
self.follower_actor_uri = None

self.leader_note_uri = None
self.follower_note_uri = None


@step
def provision_actors(self):
self.leader_actor_uri = self.sender_node.obtain_actor_document_uri()
assert self.leader_actor_uri

self.follower_actor_uri = self.receiver_node.obtain_actor_document_uri()
assert self.follower_actor_uri


@step
def leader_creates_note(self):
self.leader_note_uri = self.leader_node.make_create_note(self.leader_actor_uri, f"Testing leader_creates_note {datetime.now()}")
assert self.leader_note_uri


@step
def follower_accesses_note(self):
self.follower_note_uri = self.follower_node.access_note(self.follower_actor_uri, self.leader_note_uri)


@step
def follower_likes_note(self):
self.follower_node.like_note(self.follower_actor_uri, self.follower_note_uri)


@step
def wait_until_note_received(self):
self.leader_node.wait_until_actor_has_received_note(self.leader_actor_uri, self.follower_note_uri)
68 changes: 68 additions & 0 deletions tests/fediverse/for0.4/reply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Tests that a note by actor A can be Replied by an actor B on a different Fediverse Node
and both see the Reply.
"""

from datetime import datetime

from feditest import AssertionFailure, InteropLevel, SpecLevel, assert_that, step, test
from feditest.protocols.fediverse import FediverseNode

@test
class ReplyTest:
def __init__(self,
leader_node: FediverseNode,
follower_node: FediverseNode
) -> None:
self.leader_node = leader_node
self.leader_actor_uri = None

self.follower_node = follower_node
self.follower_actor_uri = None

self.leader_note_uri = None
self.follower_reply_uri = None
self.reply_content = f'Testing follower_replies_to_note {datetime.now()}'


@step
def provision_actors(self):
self.leader_actor_uri = self.leader_node.obtain_actor_document_uri()
assert self.leader_actor_uri

self.follower_actor_uri = self.follower_node.obtain_actor_document_uri()
assert self.follower_actor_uri


@step
def leader_creates_note(self):
self.leader_note_uri = self.leader_node.make_create_note(self.leader_actor_uri, f"Testing leader_creates_note {datetime.now()}")
assert self.leader_note_uri # We expect that this works: tests the leader_node Node implementation


@step
def follower_replies_to_note(self):
# This may throw an exception if the follower_node could not find the leader_note
self.follower_reply_uri = self.follower_node.make_reply_note(self.follower_actor_uri, self.leader_note_uri, self.reply_content)
assert self.follower_reply_uri # We expect that this works: tests the follower_node Node implementation


@step
def wait_until_reply_received_by_follower(self):
received_content = self.follower_node.wait_until_actor_has_received_note(self.follower_actor_uri, self.follower_reply_uri)
assert self.reply_content in received_content # We expect that this works: tests the follower_node Node implementation


@step
def wait_until_reply_received_by_leader(self):
try:
received_content = self.leader_node.wait_until_actor_has_received_note(self.leader_actor_uri, self.follower_reply_uri)

except TimeoutError as e:
raise AssertionFailure(SpecLevel.MUST, InteropLevel.PROBLEM, e)

if self.reply_content not in received_content:
raise AssertionFailure(SpecLevel.MUST, InteropLevel.PROBLEM, f'Received reply does not contain payload: "{ received_content }".')

if self.reply_content != received_content:
raise AssertionFailure(SpecLevel.IMPLIED, InteropLevel.DEGRADED, f'Received reply modified from original: "{ received_content }".')

0 comments on commit 9f9edb6

Please sign in to comment.