Skip to content

Commit

Permalink
Clean up FediverseNode API
Browse files Browse the repository at this point in the history
Reorder methods on FediverseNode for better comprehensibility (#395)
Add some FediverseNode methods for next set of tests
Rename account_id_*validate to acct_uri_*validate for consistency
Add list-of validation functions

Co-authored-by: Johannes Ernst <git@j12t.org>
  • Loading branch information
jernst and Johannes Ernst authored Oct 17, 2024
1 parent 116ad93 commit 23e8ef3
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 187 deletions.
130 changes: 96 additions & 34 deletions src/feditest/nodedrivers/fallback/fediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,17 @@
FediverseNonExistingAccount
)
from feditest.testplan import TestPlanConstellationNode, TestPlanNodeAccountField, TestPlanNodeNonExistingAccountField
from feditest.utils import appname_validate, boolean_parse_validate, hostname_validate, https_uri_validate, prompt_user, prompt_user_parse_validate
from feditest.utils import (
acct_uri_list_validate,
acct_uri_validate,
appname_validate,
boolean_parse_validate,
hostname_validate,
https_uri_list_validate,
https_uri_validate,
prompt_user,
prompt_user_parse_validate
)


class FallbackFediverseNode(FediverseNode):
Expand Down Expand Up @@ -64,6 +74,38 @@ def obtain_non_existing_actor_acct_uri(self, rolename: str | None = None ) -> st
return non_account.actor_acct_uri


# Python 3.12 @override
def make_follow(self, actor_acct_uri: str, to_follow_actor_acct_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" follow actor "{ to_follow_actor_acct_uri }"'
+ ' and hit return when done.')


def make_unfollow(self, actor_acct_uri: str, following_actor_acct_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" unfollow actor "{ following_actor_acct_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def actor_is_following_actor(self, actor_acct_uri: str, leader_actor_acct_uri: str) -> bool:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", is actor "{ actor_acct_uri }" following actor "{ leader_actor_acct_uri }"?'
+ ' Enter "true" or "false".',
parse_validate=boolean_parse_validate)
return answer


# Python 3.12 @override
def actor_is_followed_by_actor(self, actor_acct_uri: str, follower_actor_acct_uri: str) -> bool:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", is actor "{ actor_acct_uri }" being followed by actor "{ follower_actor_acct_uri }"?'
+ ' Enter "true" or "false".',
parse_validate=boolean_parse_validate)
return answer

# All other follow-related methods: We leave the NotImplementedByNodeError raised by the superclass until we have a better idea :-)

# Python 3.12 @override
def make_create_note(self, actor_acct_uri: str, content: str, deliver_to: list[str] | None = None) -> str:
if deliver_to :
Expand All @@ -80,72 +122,92 @@ def make_create_note(self, actor_acct_uri: str, content: str, deliver_to: list[s
parse_validate=https_uri_validate)


# Python 3.12 @override
def update_note(self, actor_acct_uri: str, note_uri: str, new_content: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" update the note at "{ note_uri }"'
+ ' with new content:"""\n{ new_content }\n"""'
+ ' and hit return when done.')


# Python 3.12 @override
def make_announce_object(self, actor_acct_uri, to_be_announced_object_uri: str) -> str:
return prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" boost "{ to_be_announced_object_uri }"'
+ ' and enter the Announce object\'s local URI:',
parse_validate=https_uri_validate)
def delete_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" delete the object at "{ object_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def make_reply_note(self, actor_acct_uri, to_be_replied_to_object_uri: str, reply_content: str) -> str:
return prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" reply to object with "{ to_be_replied_to_object_uri }"'
+ ' and enter the Announce object\'s URI when created.'
+ ' and enter the reply note\'s URI when created.'
+ f' Reply content:"""\n{ reply_content }\n"""',
parse_validate=https_uri_validate)


# Python 3.12 @override
def make_follow(self, actor_acct_uri: str, to_follow_actor_acct_uri: str) -> None:
def like_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" follow actor "{ to_follow_actor_acct_uri }"'
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" like the object at "{ object_uri }"'
+ ' and hit return when done.')


# Python 3.12 @override
def announce_object(self, actor_acct_uri: str, object_uri: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" announce/reblog/boost the object at "{ object_uri }"'
+ ' and hit return when done.')

# We leave the NotImplementedByNodeError raised by the superclass for all other follow-related actions
# until we have a better idea :-)

# Python 3.12 @override
def actor_has_received_note(self, actor_acct_uri: str, object_uri: str) -> str | None:
def actor_has_received_object(self, actor_acct_uri: str, object_uri: str) -> str | None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", has actor "{ actor_acct_uri }" received the note "{ object_uri }"?'
+ ' Enter the content of the note, or leave empty if it didn\'t happen.')
if answer:
return answer
return None
f'On FediverseNode "{ self.hostname }", has actor "{ actor_acct_uri }" received the object "{ object_uri }"?'
+ ' Enter the content of the object, or leave empty if it didn\'t happen.')
return answer if answer else None


# Python 3.12 @override
def actor_is_following_actor(self, actor_acct_uri: str, leader_actor_acct_uri: str) -> bool:
def note_content(self, actor_acct_uri: str, note_uri: str) -> str | None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access note "{ note_uri }" and enter its content.')
return answer if answer else None


# Python 3.12 @override
def object_author(self, actor_acct_uri: str, object_uri: str) -> str | None:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", is actor "{ actor_acct_uri }" following actor "{ leader_actor_acct_uri }"?'
+ ' Enter "true" or "false".',
parse_validate=boolean_parse_validate)
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access object "{ object_uri }" and enter the acct URI of the object\'s author.',
parse_validate=acct_uri_validate)
return answer


# Python 3.12 @override
def note_has_direct_reply(self, actor_acct_uri: str, note_uri: str, reply_uri: str) -> str | None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", does actor "{ actor_acct_uri }" see that note "{ note_uri }" has reply "{ reply_uri }"?'
+ ' Enter the reply content.')
return answer if answer else None
def direct_replies_to_object(self, actor_acct_uri: str, object_uri: str) -> list[str]:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access object "{ object_uri }"'
+ ' and enter the https URIs of all objects that directly reply to it (space-separated list).',
parse_validate=https_uri_list_validate)
return answer.split()


# Python 3.12 @override
def access_note(self, actor_acct_uri: str, note_uri: str) -> str | None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access note "{ note_uri }" and enter its content.')
return answer if answer else None
def object_likers(self, actor_acct_uri: str, object_uri: str) -> list[str]:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access object "{ object_uri }"'
+ ' and enter the acct URIs of all accounts that like it (space-separated list).',
parse_validate=acct_uri_list_validate)
return answer.split()


# Python 3.12 @override
def update_note(self, actor_acct_uri: str, note_uri: str, new_content: str) -> None:
prompt_user(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" update the object at "{ note_uri }"'
+ ' with new content:"""\n{ new_content }\n"""')
def object_announcers(self, actor_acct_uri: str, object_uri: str) -> list[str]:
answer = prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", have actor "{ actor_acct_uri }" access object "{ object_uri }"'
+ ' and enter the acct URIs of all accounts that have announced/reblogged/boosted it (space-separated list).',
parse_validate=acct_uri_list_validate)
return answer.split()


# From WebFingerServer
Expand Down
Loading

0 comments on commit 23e8ef3

Please sign in to comment.