Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move polling functionality #390

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ tests : tests.unit tests.smoke
tests.unit :
$(VENV)/bin/pytest -v

tests.smoke : tests.smoke.webfinger tests.smoke.fediverse

# Run WordPress tests first: they run faster as installation is faster
tests.smoke : tests.smoke.webfinger tests.smoke.api tests.smoke.fediverse

tests.smoke.webfinger :
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/webfinger.session.json --node client=tests.smoke/imp.node.json --node server=tests.smoke/wordpress.ubos.node.json $(DOMAIN)
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/webfinger.session.json --node client=tests.smoke/imp.node.json --node server=tests.smoke/mastodon.ubos.node.json $(DOMAIN)

tests.smoke.fediverse :
tests.smoke.api :
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/mastodon_api.session.json --node server=tests.smoke/wordpress.ubos.node.json $(DOMAIN)
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/mastodon_api.session.json --node server=tests.smoke/mastodon.ubos.node.json $(DOMAIN)

tests.smoke.fediverse :
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/mastodon_api_mastodon_api.session.json --node leader_node=tests.smoke/mastodon.ubos.node.json --node follower_node=tests.smoke/mastodon.ubos.node.json $(DOMAIN)
$(FEDITEST) run --testsdir tests.smoke/tests --session tests.smoke/mastodon_api_mastodon_api.session.json --node leader_node=tests.smoke/wordpress.ubos.node.json --node follower_node=tests.smoke/mastodon.ubos.node.json $(DOMAIN)

Expand All @@ -77,4 +77,4 @@ release :
@echo The actual push to pypi.org you need to do manually. Enter:
@echo venv.release/bin/twine upload dist/*

.PHONY: all default venv build lint tests tests.unit tests.smoke tests.smoke.webfinger tests.smoke.fediverse release
.PHONY: all default venv build lint tests tests.unit tests.smoke tests.smoke.webfinger tests.smoke.api tests.smoke.fediverse release
26 changes: 26 additions & 0 deletions src/feditest/disabled.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This is a little hack, but useful.
# The problem:
# You have a file that contains some @tests and maybe some @steps inside @tests. You want to temporarily disable them.
# You can go through the file, and change all the @test and @step annotations.
# Or, you can change the import statement from something like:
# from feditest import AssertionFailure, InteropLevel, SpecLevel, step, test
# to
# from feditest.disabled import AssertionFailure, InteropLevel, SpecLevel, step, test
#

from typing import Callable

from feditest import AssertionFailure, InteropLevel, SpecLevel, all_node_drivers, all_tests, assert_that, nodedriver # noqa: F401

def test(to_register: Callable[..., None] | type) -> Callable[..., None] | type:
"""
Disabled: do nothing
"""
return to_register


def step(to_register: Callable[..., None]) -> Callable[..., None]:
"""
Disabled: do nothing
"""
return to_register
8 changes: 0 additions & 8 deletions src/feditest/nodedrivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,3 @@ class NodeSpecificationInvalidError(RuntimeError):
"""
def __init__(self, node_driver: NodeDriver, parameter: str, details: str ):
super().__init__(f"Node specification is invalid for {node_driver}, parameter {parameter}: {details}" )


class TimeoutException(RuntimeError):
"""
A result has not arrived within the expected time period.
"""
def __init__(self, msg: str, timeout: float):
super().__init__(f'{ msg } (timeout: { timeout })')
84 changes: 33 additions & 51 deletions src/feditest/nodedrivers/fallback/fediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
NodeDriver,
NonExistingAccount,
OutOfAccountsException,
TimeoutException,
APP_PAR,
APP_VERSION_PAR,
HOSTNAME_PAR
Expand All @@ -28,24 +27,24 @@
FediverseNonExistingAccount
)
from feditest.testplan import TestPlanConstellationNode, TestPlanNodeAccountField, TestPlanNodeNonExistingAccountField
from feditest.utils import appname_validate, boolean_parse_validate, hostname_validate, https_uri_validate, prompt_user
from feditest.utils import appname_validate, boolean_parse_validate, hostname_validate, https_uri_validate, prompt_user, prompt_user_parse_validate


class FallbackFediverseNode(FediverseNode):
# Python 3.12 @override
def provision_account_for_role(self, role: str | None = None) -> Account | None:
userid = cast(str, prompt_user(
userid = prompt_user_parse_validate(
f'Node { self }:'
+ f' for the account with account role "{ role }", enter its userid (the user part of the acct: URI) (node account field "{ USERID_ACCOUNT_FIELD.name }"): ',
parse_validate=userid_validate))
parse_validate=userid_validate)
return FediverseAccount(role, userid)


def provision_non_existing_account_for_role(self, role: str | None = None) -> NonExistingAccount | None:
userid = cast(str, prompt_user(
userid = prompt_user_parse_validate(
f'Node { self }:'
+ f' provide the userid of a non-existing account with account role "{ role }" (the user part of the with acct: URI) (node non_existing_account field "{ USERID_NON_EXISTING_ACCOUNT_FIELD.name }"): ',
parse_validate=userid_validate))
parse_validate=userid_validate)
return FediverseNonExistingAccount(role, userid)


Expand All @@ -68,32 +67,35 @@ def obtain_non_existing_actor_acct_uri(self, rolename: str | None = None ) -> st
# 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 :
return cast(str, prompt_user(
return prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" create a Note'
+ ' to be delivered to ' + ", ".join(deliver_to)
+ ' and enter its URI when created.'
+ f' Note content:"""\n{ content }\n"""' ))
return cast(str, prompt_user(
+ f' Note content:"""\n{ content }\n"""',
parse_validate=https_uri_validate)
return prompt_user_parse_validate(
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" create a Note'
+ ' and enter its URI when created.'
+ f' Note content:"""\n{ content }\n"""' ))
+ f' Note content:"""\n{ content }\n"""',
parse_validate=https_uri_validate)



# Python 3.12 @override
def make_announce_object(self, actor_acct_uri, to_be_announced_object_uri: str) -> str:
return cast(str, prompt_user(
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))
parse_validate=https_uri_validate)


# Python 3.12 @override
def make_reply_note(self, actor_acct_uri, to_be_replied_to_object_uri: str, reply_content: str) -> str:
return cast(str, prompt_user(
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.'
+ f' Reply content:"""\n{ reply_content }\n"""' ))
+ f' Reply content:"""\n{ reply_content }\n"""',
parse_validate=https_uri_validate)


# Python 3.12 @override
Expand All @@ -102,48 +104,26 @@ def make_follow(self, actor_acct_uri: str, to_follow_actor_acct_uri: str) -> Non
f'On FediverseNode "{ self.hostname }", make actor "{ actor_acct_uri }" follow actor "{ to_follow_actor_acct_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 wait_until_actor_is_following_actor(self, actor_acct_uri: str, to_be_followed_actor_acct_uri: str, max_wait: float = 5.) -> None:
def actor_has_received_note(self, actor_acct_uri: str, object_uri: str) -> str | None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", wait until actor "{ actor_acct_uri }" is following actor "{ to_be_followed_actor_acct_uri }"'
+ ' and enter "true"; "false" if it didn\'t happen.',
parse_validate=boolean_parse_validate)
if not answer:
raise TimeoutException(f'Actor { actor_acct_uri } not following actor { to_be_followed_actor_acct_uri}.', max_wait)


# Python 3.12 @override
def wait_until_actor_is_followed_by_actor(self, actor_acct_uri: str, to_be_following_actor_acct_uri: str, max_wait: float = 5.) -> None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", wait until actor "{ actor_acct_uri }" is followed by actor "{ to_be_following_actor_acct_uri }"'
+ ' and enter "true"; "false" if it didn\'t happen.',
parse_validate=boolean_parse_validate)
if not answer:
raise TimeoutException(f'Actor { actor_acct_uri } not followed by actor { to_be_following_actor_acct_uri}.', max_wait)
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


# Python 3.12 @override
def wait_until_actor_is_unfollowing_actor(self, actor_acct_uri: str, to_be_unfollowed_actor_acct_uri: str, max_wait: float = 5.) -> None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", wait until actor "{ actor_acct_uri }" is not following any more actor "{ to_be_unfollowed_actor_acct_uri }"'
+ ' and enter "true"; "false" if it didn\'t happen.',
parse_validate=boolean_parse_validate)
if not answer:
raise TimeoutException(f'Actor { actor_acct_uri } still following actor { to_be_unfollowed_actor_acct_uri}.', max_wait)


# Python 3.12 @override
def wait_until_actor_is_unfollowed_by_actor(self, actor_acct_uri: str, to_be_unfollowing_actor_acct_uri: str, max_wait: float = 5.) -> None:
answer = prompt_user(
f'On FediverseNode "{ self.hostname }", wait until in actor "{ actor_acct_uri }" is not followed any more by actor "{ to_be_unfollowing_actor_acct_uri }"'
+ ' and enter "true"; "false" if it didn\'t happen.',
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)
if not answer:
raise TimeoutException(f'Actor { actor_acct_uri } is still followed by actor { to_be_unfollowing_actor_acct_uri}.', max_wait)
return answer

# From WebFingerServer

Expand Down Expand Up @@ -189,11 +169,13 @@ def create_configuration_account_manager(self, rolename: str, test_plan_node: Te
hostname = test_plan_node.parameter(HOSTNAME_PAR)

if not hostname:
hostname = prompt_user(f'Enter the hostname for the Node of constellation role "{ rolename }" (node parameter "hostname"): ',
parse_validate=hostname_validate)
hostname = prompt_user_parse_validate(
f'Enter the hostname for the Node of constellation role "{ rolename }" (node parameter "hostname"): ',
parse_validate=hostname_validate)
if not app:
app = prompt_user(f'Enter the name of the app at constellation role "{ rolename }" and hostname "{ hostname }" (node parameter "app"): ',
parse_validate=appname_validate)
app = prompt_user_parse_validate(
f'Enter the name of the app at constellation role "{ rolename }" and hostname "{ hostname }" (node parameter "app"): ',
parse_validate=appname_validate)

accounts : list[Account] = []
if test_plan_node.accounts:
Expand Down
5 changes: 3 additions & 2 deletions src/feditest/nodedrivers/manual/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ class FediverseManualNodeDriver(AbstractFallbackFediverseNodeDriver):
"""
# Python 3.12 @override
def _provision_node(self, rolename: str, config: NodeConfiguration, account_manager: AccountManager | None) -> FediverseNode:
prompt_user(f'Manually provision the Node for constellation role { rolename }'
+ f' at host { config.hostname } with app { config.app } and hit return when done.')
prompt_user(
f'Manually provision the Node for constellation role { rolename }'
+ f' at host { config.hostname } with app { config.app } and hit return when done.')
return FallbackFediverseNode(rolename, config, account_manager)


Expand Down
Loading
Loading