Skip to content

Commit

Permalink
Add test for imports of 'all' controls
Browse files Browse the repository at this point in the history
Test import of all controls of a specific level.
  • Loading branch information
yuumasato committed Aug 27, 2024
1 parent 2438f12 commit 5d69b16
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/unit/ssg-module/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,37 @@ def test_policy_parse_from_ours_and_foreign():
assert "really_ours" in control.selections
assert "foreign" in control.selections

def test_policy_parse_all_foreign():
main_control_dict = dict(id="top", controls=["foreign:all:level_1", "ours", "P:ours_qualified"])
main_subcontrol_dicts = [dict(id="ours", rules=["ours"]), dict(id="ours_qualified", rules=["really_ours"])]
foreign_control_dicts = [dict(id="req1", rules=["foreign_1"], levels=["level_1"]),
dict(id="req2", rules=["foreign_2"], levels=["level_1", "level_2"]),
dict(id="req3", rules=["foreign_3"], levels=["level_2"])]

main_policy = ssg.controls.Policy("")
main_policy.id = "P"
main_policy.save_controls_tree([main_control_dict] + main_subcontrol_dicts)

foreign_policy = ssg.controls.Policy("")
foreign_policy.id = "foreign"
level1 = ssg.controls.Level.from_level_dict(dict(id="level_1"))
level2 = ssg.controls.Level.from_level_dict(dict(id="level_2"))

foreign_policy.levels = [level1, level2]
foreign_policy.levels_by_id = {"level_1": level1, "level_2": level2}
foreign_policy.save_controls_tree(foreign_control_dicts)

controls_manager = ssg.controls.ControlsManager("", dict())
controls_manager.policies[main_policy.id] = main_policy
controls_manager.policies[foreign_policy.id] = foreign_policy

controls_manager.resolve_controls()
control = controls_manager.get_control("P", "top")
assert "ours" in control.selections
assert "really_ours" in control.selections
assert "foreign_1" in control.selections
assert "foreign_2" in control.selections
assert "foreign_3" not in control.selections

def test_policy_parse_from_referenced(minimal_empty_controls, one_simple_subcontrol):
nested_controls = minimal_empty_controls
Expand Down

0 comments on commit 5d69b16

Please sign in to comment.