Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Closes fediverse-devnet#285
Better error messages when Node parameter fields or user attributes are missing or invalid
  • Loading branch information
Johannes Ernst committed Sep 30, 2024
1 parent dd8246a commit d8c0924
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 49 deletions.
28 changes: 16 additions & 12 deletions src/feditest/nodedrivers/fallback/fediverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def __init__(self, role: str | None, uri: str, actor_uri: str | None):


@staticmethod
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "account" dict of TestPlanConstellationNode
"""
uri = URI_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
actor_uri = ACTOR_URI_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, f'NodeDriver { node_driver }: ')
uri = URI_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
actor_uri = ACTOR_URI_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, context_msg)

# If actor_uri was not given, we cannot perform a WebFinger query here: the Node may not exist yet

Expand Down Expand Up @@ -122,13 +122,13 @@ def __init__(self, role: str | None, uri: str, actor_uri: str | None):


@staticmethod
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "non_existing_account" dict of TestPlanConstellationNode
"""
uri = URI_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')
actor_uri = ACTOR_URI_NON_EXISTING_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_NON_EXISTING_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')
uri = URI_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, context_msg)
actor_uri = ACTOR_URI_NON_EXISTING_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, context_msg)
role = ROLE_NON_EXISTING_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, context_msg)

# We cannot perform a WebFinger query: account does not exist

Expand Down Expand Up @@ -314,13 +314,17 @@ def create_configuration_account_manager(self, rolename: str, test_plan_node: Te

accounts : list[Account] = []
if test_plan_node.accounts:
for account_info in test_plan_node.accounts:
accounts.append(FallbackFediverseAccount.create_from_account_info_in_testplan(account_info, self))
for index, account_info in enumerate(test_plan_node.accounts):
accounts.append(FallbackFediverseAccount.create_from_account_info_in_testplan(
account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Account { index }: '))

non_existing_accounts : list[NonExistingAccount] = []
if test_plan_node.non_existing_accounts:
for non_existing_account_info in test_plan_node.non_existing_accounts:
non_existing_accounts.append(FallbackFediverseNonExistingAccount.create_from_non_existing_account_info_in_testplan(non_existing_account_info, self))
for index, non_existing_account_info in enumerate(test_plan_node.non_existing_accounts):
non_existing_accounts.append(FallbackFediverseNonExistingAccount.create_from_non_existing_account_info_in_testplan(
non_existing_account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Non-existing account { index }: '))

return (
NodeConfiguration(
Expand Down
34 changes: 18 additions & 16 deletions src/feditest/nodedrivers/mastodon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ def mastodon_user_client(self) -> Mastodon:

class MastodonAccount(AccountOnNodeWithMastodonAPI): # this is intended to be abstract
@staticmethod
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "account" dict of TestPlanConstellationNode
"""
userid = USERID_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, f'NodeDriver { node_driver }: ')
userid = USERID_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, context_msg)
oauth_token = OAUTH_TOKEN_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, context_msg)

oauth_token = OAUTH_TOKEN_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, f'NodeDriver { node_driver }: ')
if oauth_token:
if EMAIL_ACCOUNT_FIELD.name in account_info_in_testplan:
raise InvalidAccountSpecificationException(
Expand All @@ -196,10 +196,9 @@ def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str
f'Specify { OAUTH_TOKEN_ACCOUNT_FIELD.name } or { PASSWORD_ACCOUNT_FIELD.name }, not both.')
return MastodonOAuthTokenAccount(role, userid, oauth_token)

else:
email = EMAIL_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
password = PASSWORD_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
return MastodonUserPasswordAccount(role, userid, password, email)
email = EMAIL_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
password = PASSWORD_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
return MastodonUserPasswordAccount(role, userid, password, email)


@property
Expand Down Expand Up @@ -270,13 +269,12 @@ def __init__(self, role: str | None, userid: str):


@staticmethod
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "non_existing_account" dict of TestPlanConstellationNode
"""
userid = USERID_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')

userid = USERID_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, context_msg)
role = ROLE_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, context_msg)
return MastodonNonExistingAccount(role, userid)


Expand Down Expand Up @@ -771,13 +769,17 @@ def create_configuration_account_manager(self, rolename: str, test_plan_node: Te

accounts : list[Account] = []
if test_plan_node.accounts:
for account_info in test_plan_node.accounts:
accounts.append(MastodonAccount.create_from_account_info_in_testplan(account_info, self))
for index, account_info in enumerate(test_plan_node.accounts):
accounts.append(MastodonAccount.create_from_account_info_in_testplan(
account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Account { index }: '))

non_existing_accounts : list[NonExistingAccount] = []
if test_plan_node.non_existing_accounts:
for non_existing_account_info in test_plan_node.non_existing_accounts:
non_existing_accounts.append(MastodonNonExistingAccount.create_from_non_existing_account_info_in_testplan(non_existing_account_info, self))
for index, non_existing_account_info in enumerate(test_plan_node.non_existing_accounts):
non_existing_accounts.append(MastodonNonExistingAccount.create_from_non_existing_account_info_in_testplan(
non_existing_account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Non-existing account { index }: '))

return (
NodeWithMastodonApiConfiguration(
Expand Down
12 changes: 8 additions & 4 deletions src/feditest/nodedrivers/mastodon/ubos.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,17 @@ def test_plan_node_non_existing_account_fields() -> list[TestPlanNodeNonExisting
def create_configuration_account_manager(self, rolename: str, test_plan_node: TestPlanConstellationNode) -> tuple[NodeConfiguration, AccountManager | None]:
accounts : list[Account] = []
if test_plan_node.accounts:
for account_info in test_plan_node.accounts:
accounts.append(MastodonAccount.create_from_account_info_in_testplan(account_info, self))
for index, account_info in enumerate(test_plan_node.accounts):
accounts.append(MastodonAccount.create_from_account_info_in_testplan(
account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Account { index }: '))

non_existing_accounts : list[NonExistingAccount] = []
if test_plan_node.non_existing_accounts:
for non_existing_account_info in test_plan_node.non_existing_accounts:
non_existing_accounts.append(MastodonNonExistingAccount.create_from_non_existing_account_info_in_testplan(non_existing_account_info, self))
for index, non_existing_account_info in enumerate(test_plan_node.non_existing_accounts):
non_existing_accounts.append(MastodonNonExistingAccount.create_from_non_existing_account_info_in_testplan(
non_existing_account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Non-existing account { index }: '))

# Once has the Node has been instantiated (we can't do that here yet): if the user did not specify at least one Account, we add the admin account

Expand Down
28 changes: 15 additions & 13 deletions src/feditest/nodedrivers/wordpress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,13 @@ def __init__(self, role: str | None, userid: str, oauth_token: str | None, inter


@staticmethod
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_account_info_in_testplan(account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "account" dict of TestPlanConstellationNode
"""
userid = USERID_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, f'NodeDriver { node_driver }: ')

oauth_token = OAUTH_TOKEN_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, f'NodeDriver { node_driver }: ')
userid = USERID_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
role = ROLE_ACCOUNT_FIELD.get_validate_from(account_info_in_testplan, context_msg)
oauth_token = OAUTH_TOKEN_ACCOUNT_FIELD.get_validate_from_or_raise(account_info_in_testplan, context_msg)
return WordPressAccount(role, userid, oauth_token)


Expand Down Expand Up @@ -146,13 +145,12 @@ def __init__(self, role: str | None, userid: str):


@staticmethod
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], node_driver: NodeDriver):
def create_from_non_existing_account_info_in_testplan(non_existing_account_info_in_testplan: dict[str, str | None], context_msg: str = ''):
"""
Parses the information provided in an "non_existing_account" dict of TestPlanConstellationNode
"""
userid = USERID_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')
role = ROLE_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, f'NodeDriver { node_driver }: ')

userid = USERID_NON_EXISTING_ACCOUNT_FIELD.get_validate_from_or_raise(non_existing_account_info_in_testplan, context_msg)
role = ROLE_ACCOUNT_FIELD.get_validate_from(non_existing_account_info_in_testplan, context_msg)
return WordPressNonExistingAccount(role, userid)


Expand Down Expand Up @@ -221,13 +219,17 @@ def create_configuration_account_manager(self, rolename: str, test_plan_node: Te

accounts : list[Account] = []
if test_plan_node.accounts:
for account_info in test_plan_node.accounts:
accounts.append(WordPressAccount.create_from_account_info_in_testplan(account_info, self))
for index, account_info in enumerate(test_plan_node.accounts):
accounts.append(WordPressAccount.create_from_account_info_in_testplan(
account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Account { index }: '))

non_existing_accounts : list[NonExistingAccount] = []
if test_plan_node.non_existing_accounts:
for non_existing_account_info in test_plan_node.non_existing_accounts:
non_existing_accounts.append(WordPressNonExistingAccount.create_from_non_existing_account_info_in_testplan(non_existing_account_info, self))
for index, non_existing_account_info in enumerate(test_plan_node.non_existing_accounts):
non_existing_accounts.append(WordPressNonExistingAccount.create_from_non_existing_account_info_in_testplan(
non_existing_account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Non-existing account { index }: '))

return (
NodeWithMastodonApiConfiguration(
Expand Down
12 changes: 8 additions & 4 deletions src/feditest/nodedrivers/wordpress/ubos.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,17 @@ def test_plan_node_non_existing_account_fields() -> list[TestPlanNodeNonExisting
def create_configuration_account_manager(self, rolename: str, test_plan_node: TestPlanConstellationNode) -> tuple[NodeConfiguration, AccountManager | None]:
accounts : list[Account] = []
if test_plan_node.accounts:
for account_info in test_plan_node.accounts:
accounts.append(WordPressAccount.create_from_account_info_in_testplan(account_info, self))
for index, account_info in enumerate(test_plan_node.accounts):
accounts.append(WordPressAccount.create_from_account_info_in_testplan(
account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Account { index }: '))

non_existing_accounts : list[NonExistingAccount] = []
if test_plan_node.non_existing_accounts:
for non_existing_account_info in test_plan_node.non_existing_accounts:
non_existing_accounts.append(WordPressNonExistingAccount.create_from_non_existing_account_info_in_testplan(non_existing_account_info, self))
for index, non_existing_account_info in enumerate(test_plan_node.non_existing_accounts):
non_existing_accounts.append(WordPressNonExistingAccount.create_from_non_existing_account_info_in_testplan(
non_existing_account_info,
f'Constellation role "{ rolename }", NodeDriver "{ self }, Non-existing account { index }: '))

# Once has the Node has been instantiated (we can't do that here yet): if the user did not specify at least one Account, we add the admin account

Expand Down

0 comments on commit d8c0924

Please sign in to comment.