Skip to content

Commit bfda1f7

Browse files
authored
Merge pull request #443 from jernst/develop
Fix invalid HTML escaping. 'role' not required in pre-existing accounts.
2 parents 3eae55e + 6383569 commit bfda1f7

File tree

5 files changed

+111
-18
lines changed

5 files changed

+111
-18
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ $(VENV) :
3838
$(VENV)/bin/pip install ruff mypy pylint
3939

4040
lint : build
41-
$(VENV)/bin/ruff check src
41+
$(VENV)/bin/ruff check
4242
MYPYPATH=src $(VENV)/bin/mypy --namespace-packages --explicit-package-bases --install-types --non-interactive src
4343
@# These options should be the same flags as in .pre-commit-config.yml, except that I can't get it to
4444
@# work there without the "--ignore-missing-imports" flag, while it does work without it here

src/feditest/testplan.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,21 @@ def properties_validate(self) -> None:
158158

159159
if self.accounts:
160160
for account in self.accounts:
161-
if 'role' not in account:
162-
raise ValueError('No role name given in account')
161+
if 'role' in account:
162+
if not account['role']:
163+
raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty')
163164

164-
if not account['role']:
165-
raise ValueError('Invalid TestPlanConstellationNode account role name: cannot be empty')
166-
167-
if not symbolic_name_validate(account['role']):
168-
raise ValueError(f'Invalid role name in account: "{ account["role" ]}')
165+
if not symbolic_name_validate(account['role']):
166+
raise ValueError(f'Invalid role name in account: "{ account["role" ]}')
169167

170168
if self.non_existing_accounts:
171169
for non_existing_account in self.non_existing_accounts:
172-
if 'role' not in non_existing_account:
173-
raise ValueError('No role name given in non_existing_account')
174-
175-
if not non_existing_account['role']:
176-
raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty')
170+
if 'role' in non_existing_account:
171+
if not non_existing_account['role']:
172+
raise ValueError('Invalid TestPlanConstellationNode non_existing_account role name: cannot be empty')
177173

178-
if not symbolic_name_validate(non_existing_account['role']):
179-
raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}')
174+
if not symbolic_name_validate(non_existing_account['role']):
175+
raise ValueError(f'Invalid role name in non_existing_account: "{ non_existing_account["role" ]}')
180176

181177

182178
@staticmethod

src/feditest/testruntranscriptserializer/templates/testplantranscript_default/partials/matrix/matrix.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{%- for test_index, ( _, test_meta ) in enumerate(sorted(transcript.test_meta.items())) %}
3434
<tr>
3535
<td class="namedesc">
36-
<span class="name">{{ permit_line_breaks_in_identifier(test_meta.name) | e }}</span>
36+
<span class="name">{{ permit_line_breaks_in_identifier(test_meta.name) | safe }}</span>
3737
{%- if test_meta.description %}
3838
<span class="description">{{ test_meta.description | e }}</span>
3939
{%- endif %}

tests.unit/test_40_fallback_fediverse_accounts_from_testplan.py renamed to tests.unit/test_40_fallback_fediverse_accounts_with_roles_from_testplan.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that
3-
specifies a FallbackFediverseNode
3+
specifies a FallbackFediverseNode. This is the test in which the Accounts have pre-assigned roles.
44
"""
55

66
from typing import cast
@@ -63,7 +63,7 @@ def test_plan_fixture() -> TestPlan:
6363
return ret
6464

6565

66-
def test_parse(test_plan_fixture: TestPlan) -> None:
66+
def test_populate(test_plan_fixture: TestPlan) -> None:
6767
"""
6868
Tests parsing the TestPlan
6969
"""
@@ -79,8 +79,14 @@ def test_parse(test_plan_fixture: TestPlan) -> None:
7979
assert acc1.role == 'role1'
8080
assert acc1.actor_acct_uri == 'acct:[email protected]'
8181

82+
acc11 = account_manager.obtain_account_by_role('role1')
83+
assert acc11 == acc1
84+
8285
non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1'))
8386
assert non_acc1
8487
assert non_acc1.role == 'nonrole1'
8588
assert non_acc1.actor_acct_uri == 'acct:[email protected]'
8689

90+
non_acc11 = account_manager.obtain_non_existing_account_by_role('nonrole1')
91+
assert non_acc11 == non_acc1
92+
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
Test that Accounts and NonExistingAccounts are parsed correctly when given in a TestPlan that
3+
specifies a FallbackFediverseNode. This is the test in which the Accounts do not have pre-assigned roles.
4+
"""
5+
6+
from typing import cast
7+
8+
import pytest
9+
10+
import feditest
11+
from feditest.nodedrivers.saas import FediverseSaasNodeDriver
12+
from feditest.protocols.fediverse import (
13+
USERID_ACCOUNT_FIELD,
14+
USERID_NON_EXISTING_ACCOUNT_FIELD,
15+
FediverseAccount,
16+
FediverseNonExistingAccount
17+
)
18+
from feditest.testplan import TestPlan, TestPlanConstellation, TestPlanConstellationNode, TestPlanSessionTemplate
19+
20+
21+
HOSTNAME = 'localhost'
22+
NODE1_ROLE = 'node1-role'
23+
24+
25+
@pytest.fixture(scope="module", autouse=True)
26+
def init():
27+
""" Clean init """
28+
feditest.all_tests = {}
29+
feditest._registered_as_test = {}
30+
feditest._registered_as_test_step = {}
31+
feditest._loading_tests = True
32+
33+
feditest._loading_tests = False
34+
feditest._load_tests_pass2()
35+
36+
37+
@pytest.fixture(autouse=True)
38+
def test_plan_fixture() -> TestPlan:
39+
node_driver = FediverseSaasNodeDriver()
40+
parameters = {
41+
'hostname' : 'example.com', # Avoid interactive question
42+
'app' : 'test-dummy' # Avoid interactive question
43+
}
44+
plan_accounts = [
45+
{
46+
USERID_ACCOUNT_FIELD.name : 'foo'
47+
}
48+
]
49+
plan_non_existing_accounts = [
50+
{
51+
USERID_NON_EXISTING_ACCOUNT_FIELD.name : 'nonfoo'
52+
}
53+
]
54+
node1 = TestPlanConstellationNode(node_driver, parameters, plan_accounts, plan_non_existing_accounts)
55+
constellation = TestPlanConstellation({ NODE1_ROLE : node1 })
56+
session_template = TestPlanSessionTemplate([])
57+
ret = TestPlan(session_template, [ constellation ])
58+
ret.properties_validate()
59+
return ret
60+
61+
62+
def test_populate(test_plan_fixture: TestPlan) -> None:
63+
"""
64+
Tests parsing the TestPlan
65+
"""
66+
node1 = test_plan_fixture.constellations[0].roles[NODE1_ROLE]
67+
node_driver = node1.nodedriver
68+
69+
node_config, account_manager = node_driver.create_configuration_account_manager(NODE1_ROLE, node1)
70+
node_driver.provision_node('test', node_config, account_manager)
71+
72+
acc1 = cast(FediverseAccount | None, account_manager.get_account_by_role('role1'))
73+
74+
assert acc1 is None
75+
76+
acc1 = account_manager.obtain_account_by_role('role1')
77+
78+
assert acc1
79+
assert acc1.role is None
80+
assert acc1.actor_acct_uri == 'acct:[email protected]'
81+
82+
non_acc1 = cast(FediverseNonExistingAccount | None, account_manager.get_non_existing_account_by_role('nonrole1'))
83+
84+
assert non_acc1 is None
85+
86+
non_acc1 = account_manager.obtain_non_existing_account_by_role('nonrole1')
87+
88+
assert non_acc1
89+
assert non_acc1.role is None
90+
assert non_acc1.actor_acct_uri == 'acct:[email protected]'
91+

0 commit comments

Comments
 (0)