diff --git a/Makefile b/Makefile index e5e794c..decc9ef 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ $(VENV) : $(VENV)/bin/pip install ruff mypy pylint lint : build - $(VENV)/bin/ruff check src + $(VENV)/bin/ruff check MYPYPATH=src $(VENV)/bin/mypy --namespace-packages --explicit-package-bases --install-types --non-interactive src @# These options should be the same flags as in .pre-commit-config.yml, except that I can't get it to @# work there without the "--ignore-missing-imports" flag, while it does work without it here diff --git a/src/feditest/testplan.py b/src/feditest/testplan.py index 76f9f5c..627767b 100644 --- a/src/feditest/testplan.py +++ b/src/feditest/testplan.py @@ -158,25 +158,21 @@ def properties_validate(self) -> None: if self.accounts: for account in self.accounts: - if 'role' not in account: - raise ValueError('No role name given in account') + if 'role' in account: + if not account['role']: + raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty') - if not account['role']: - raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty') - - if not symbolic_name_validate(account['role']): - raise ValueError(f'Invalid role name in account: "{ account["role" ]}') + if not symbolic_name_validate(account['role']): + raise ValueError(f'Invalid role name in account: "{ account["role" ]}') if self.non_existing_accounts: for non_existing_account in self.non_existing_accounts: - if 'role' not in non_existing_account: - raise ValueError('No role name given in non_existing_account') - - if not non_existing_account['role']: - raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty') + if 'role' in non_existing_account: + if not non_existing_account['role']: + raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty') - if not symbolic_name_validate(non_existing_account['role']): - raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}') + if not symbolic_name_validate(non_existing_account['role']): + raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}') @staticmethod diff --git a/src/feditest/testruntranscriptserializer/templates/testplantranscript_default/partials/matrix/matrix.jinja2 b/src/feditest/testruntranscriptserializer/templates/testplantranscript_default/partials/matrix/matrix.jinja2 index a129a29..c9c78bc 100644 --- a/src/feditest/testruntranscriptserializer/templates/testplantranscript_default/partials/matrix/matrix.jinja2 +++ b/src/feditest/testruntranscriptserializer/templates/testplantranscript_default/partials/matrix/matrix.jinja2 @@ -33,7 +33,7 @@ {%- for test_index, ( _, test_meta ) in enumerate(sorted(transcript.test_meta.items())) %} - {{ permit_line_breaks_in_identifier(test_meta.name) | e }} + {{ permit_line_breaks_in_identifier(test_meta.name) | safe }} {%- if test_meta.description %} {{ test_meta.description | e }} {%- endif %} diff --git a/tests.unit/test_40_fallback_fediverse_accounts_from_testplan.py b/tests.unit/test_40_fallback_fediverse_accounts_with_roles_from_testplan.py similarity index 87% rename from tests.unit/test_40_fallback_fediverse_accounts_from_testplan.py rename to tests.unit/test_40_fallback_fediverse_accounts_with_roles_from_testplan.py index b98caf9..e886493 100644 --- a/tests.unit/test_40_fallback_fediverse_accounts_from_testplan.py +++ b/tests.unit/test_40_fallback_fediverse_accounts_with_roles_from_testplan.py @@ -1,6 +1,6 @@ """ Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that -specifies a FallbackFediverseNode +specifies a FallbackFediverseNode. This is the test in which the Accounts have pre-assigned roles. """ from typing import cast @@ -63,7 +63,7 @@ def test_plan_fixture() -> TestPlan: return ret -def test_parse(test_plan_fixture: TestPlan) -> None: +def test_populate(test_plan_fixture: TestPlan) -> None: """ Tests parsing the TestPlan """ @@ -79,8 +79,14 @@ def test_parse(test_plan_fixture: TestPlan) -> None: assert acc1.role == 'role1' assert acc1.actor_acct_uri == 'acct:foo@example.com' + acc11 = account_manager.obtain_account_by_role('role1') + assert acc11 == acc1 + non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1')) assert non_acc1 assert non_acc1.role == 'nonrole1' assert non_acc1.actor_acct_uri == 'acct:nonfoo@example.com' + non_acc11 = account_manager.obtain_non_existing_account_by_role('nonrole1') + assert non_acc11 == non_acc1 + diff --git a/tests.unit/test_40_fallback_fediverse_accounts_without_roles_from_testplan.py b/tests.unit/test_40_fallback_fediverse_accounts_without_roles_from_testplan.py new file mode 100644 index 0000000..46e196d --- /dev/null +++ b/tests.unit/test_40_fallback_fediverse_accounts_without_roles_from_testplan.py @@ -0,0 +1,91 @@ +""" +Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that +specifies a FallbackFediverseNode. This is the test in which the Accounts do not have pre-assigned roles. +""" + +from typing import cast + +import pytest + +import feditest +from feditest.nodedrivers.saas import FediverseSaasNodeDriver +from feditest.protocols.fediverse import ( + USERID_ACCOUNT_FIELD, + USERID_NON_EXISTING_ACCOUNT_FIELD, + FediverseAccount, + FediverseNonExistingAccount +) +from feditest.testplan import TestPlan, TestPlanConstellation, TestPlanConstellationNode, TestPlanSessionTemplate + + +HOSTNAME = 'localhost' +NODE1_ROLE = 'node1-role' + + +@pytest.fixture(scope="module", autouse=True) +def init(): + """ Clean init """ + feditest.all_tests = {} + feditest._registered_as_test = {} + feditest._registered_as_test_step = {} + feditest._loading_tests = True + + feditest._loading_tests = False + feditest._load_tests_pass2() + + +@pytest.fixture(autouse=True) +def test_plan_fixture() -> TestPlan: + node_driver = FediverseSaasNodeDriver() + parameters = { + 'hostname' : 'example.com', # Avoid interactive question + 'app' : 'test-dummy' # Avoid interactive question + } + plan_accounts = [ + { + USERID_ACCOUNT_FIELD.name : 'foo' + } + ] + plan_non_existing_accounts = [ + { + USERID_NON_EXISTING_ACCOUNT_FIELD.name : 'nonfoo' + } + ] + node1 = TestPlanConstellationNode(node_driver, parameters, plan_accounts, plan_non_existing_accounts) + constellation = TestPlanConstellation({ NODE1_ROLE : node1 }) + session_template = TestPlanSessionTemplate([]) + ret = TestPlan(session_template, [ constellation ]) + ret.properties_validate() + return ret + + +def test_populate(test_plan_fixture: TestPlan) -> None: + """ + Tests parsing the TestPlan + """ + node1 = test_plan_fixture.constellations[0].roles[NODE1_ROLE] + node_driver = node1.nodedriver + + node_config, account_manager = node_driver.create_configuration_account_manager(NODE1_ROLE, node1) + node_driver.provision_node('test', node_config, account_manager) + + acc1 = cast(FediverseAccount | None, account_manager.get_account_by_role('role1')) + + assert acc1 is None + + acc1 = account_manager.obtain_account_by_role('role1') + + assert acc1 + assert acc1.role is None + assert acc1.actor_acct_uri == 'acct:foo@example.com' + + non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1')) + + assert non_acc1 is None + + non_acc1 = account_manager.obtain_non_existing_account_by_role('nonrole1') + + assert non_acc1 + assert non_acc1.role is None + assert non_acc1.actor_acct_uri == 'acct:nonfoo@example.com' +