Change reco default value, Slide test cases

This commit is contained in:
Tobias Hößl 2019-02-14 16:35:25 +01:00 committed by Emanuel Schütze
parent 35cd49e4fe
commit 7b2e116f51
2 changed files with 212 additions and 26 deletions

View File

@ -31,6 +31,7 @@ def get_state(
f"motion {motion['id']} can not be on the state with id {state_id}"
)
def get_amendment_merge_into_motion(all_data, motion, amendment):
"""
HINT: This implementation should be consistent to isAccepted() in ViewMotionAmendedParagraph.ts
@ -38,33 +39,38 @@ def get_amendment_merge_into_motion(all_data, motion, amendment):
if amendment["state_id"] is None:
return 0
state = get_state(
all_data, motion, amendment["state_id"]
)
if state["merge_amendment_into_final"] == -1 or state["merge_amendment_into_final"] == 1:
state = get_state(all_data, motion, amendment["state_id"])
if (
state["merge_amendment_into_final"] == -1
or state["merge_amendment_into_final"] == 1
):
return state["merge_amendment_into_final"]
if amendment["recommendation_id"] is None:
return 0
recommendation = get_state(
all_data, motion, amendment["recommendation_id"]
)
recommendation = get_state(all_data, motion, amendment["recommendation_id"])
return recommendation["merge_amendment_into_final"]
def get_amendments_for_motion(motion, all_data):
amendment_data = []
for amendment_id, amendment in all_data["motions/motion"].items():
if amendment["parent_id"] == motion["id"]:
merge_amendment_into_final = get_amendment_merge_into_motion(all_data, motion, amendment)
amendment_data.append({
"id": amendment["id"],
"identifier": amendment["identifier"],
"title": amendment["title"],
"amendment_paragraphs": amendment["amendment_paragraphs"],
"merge_amendment_into_final": merge_amendment_into_final,
})
merge_amendment_into_final = get_amendment_merge_into_motion(
all_data, motion, amendment
)
amendment_data.append(
{
"id": amendment["id"],
"identifier": amendment["identifier"],
"title": amendment["title"],
"amendment_paragraphs": amendment["amendment_paragraphs"],
"merge_amendment_into_final": merge_amendment_into_final,
}
)
return amendment_data
def get_amendment_base_motion(amendment, all_data):
try:
motion = all_data["motions/motion"][amendment["parent_id"]]
@ -78,17 +84,18 @@ def get_amendment_base_motion(amendment, all_data):
"text": motion["text"],
}
def get_amendment_base_statute(amendment, all_data):
try:
statute = all_data["motions/statute-paragraph"][amendment["statute_paragraph_id"]]
statute = all_data["motions/statute-paragraph"][
amendment["statute_paragraph_id"]
]
except KeyError:
statute_id = amendment["statute_paragraph_id"]
raise ProjectorElementException(f"statute with id {statute_id} does not exist")
return {
"title": statute["title"],
"text": statute["text"],
}
return {"title": statute["title"], "text": statute["text"]}
def motion_slide(all_data: AllData, element: Dict[str, Any]) -> Dict[str, Any]:
"""
@ -109,7 +116,7 @@ def motion_slide(all_data: AllData, element: Dict[str, Any]) -> Dict[str, Any]:
* change_recommendations
* submitter
"""
mode = element.get("mode", "original")
mode = element.get("mode", get_config(all_data, "motions_recommendation_text_mode"))
motion_id = element.get("id")
if motion_id is None:
@ -126,9 +133,8 @@ def motion_slide(all_data: AllData, element: Dict[str, Any]) -> Dict[str, Any]:
motions_preamble = get_config(all_data, "motions_preamble")
if motion["statute_paragraph_id"]:
print("statute")
change_recommendations = []
amendments = []
change_recommendations = [] # type: ignore
amendments = [] # type: ignore
base_motion = None
base_statute = get_amendment_base_statute(motion, all_data)
elif bool(motion["parent_id"]) and motion["amendment_paragraphs"]:
@ -137,7 +143,11 @@ def motion_slide(all_data: AllData, element: Dict[str, Any]) -> Dict[str, Any]:
base_motion = get_amendment_base_motion(motion, all_data)
base_statute = None
else:
change_recommendations = list(filter(lambda reco: reco["internal"] == False, motion["change_recommendations"]))
change_recommendations = list(
filter(
lambda reco: reco["internal"] is False, motion["change_recommendations"]
)
)
amendments = get_amendments_for_motion(motion, all_data)
base_motion = None
base_statute = None

View File

@ -74,7 +74,99 @@ def all_data():
"weight": 10000,
"created": "2019-01-19T18:37:34.741336+01:00",
"last_modified": "2019-01-19T18:37:34.741368+01:00",
}
"change_recommendations": [
{
"id": 1,
"motion_id": 1,
"rejected": False,
"internal": True,
"type": 0,
"other_description": "",
"line_from": 1,
"line_to": 2,
"text": "internal new motion text",
"creation_time": "2019-02-09T09:54:06.256378+01:00",
},
{
"id": 2,
"motion_id": 1,
"rejected": False,
"internal": False,
"type": 0,
"other_description": "",
"line_from": 1,
"line_to": 2,
"text": "public new motion text",
"creation_time": "2019-02-09T09:54:06.256378+01:00",
},
],
},
2: {
"id": 2,
"identifier": "Ä1",
"title": "Amendment for 12345",
"text": "",
"amendment_paragraphs": ["New motion text"],
"modified_final_version": "",
"reason": "",
"parent_id": 1,
"category_id": None,
"comments": [],
"motion_block_id": None,
"origin": "",
"submitters": [{"id": 4, "user_id": 1, "motion_id": 1, "weight": 1}],
"supporters_id": [],
"state_id": 1,
"state_extension": None,
"state_access_level": 0,
"statute_paragraph_id": None,
"workflow_id": 1,
"recommendation_id": None,
"recommendation_extension": None,
"tags_id": [],
"attachments_id": [],
"polls": [],
"agenda_item_id": 4,
"log_messages": [],
"sort_parent_id": None,
"weight": 10000,
"created": "2019-01-19T18:37:34.741336+01:00",
"last_modified": "2019-01-19T18:37:34.741368+01:00",
"change_recommendations": [],
},
3: {
"id": 3,
"identifier": None,
"title": "Statute amendment for §1 Preamble",
"text": "<p>Some other preamble text</p>",
"amendment_paragraphs": None,
"modified_final_version": "",
"reason": "",
"parent_id": None,
"category_id": None,
"comments": [],
"motion_block_id": None,
"origin": "",
"submitters": [{"id": 4, "user_id": 1, "motion_id": 1, "weight": 1}],
"supporters_id": [],
"state_id": 1,
"state_extension": None,
"state_access_level": 0,
"statute_paragraph_id": 1,
"workflow_id": 1,
"recommendation_id": None,
"recommendation_extension": None,
"tags_id": [],
"attachments_id": [],
"polls": [],
"agenda_item_id": 4,
"log_messages": [],
"sort_parent_id": None,
"weight": 10000,
"created": "2019-01-19T18:37:34.741336+01:00",
"last_modified": "2019-01-19T18:37:34.741368+01:00",
"change_recommendations": [],
},
}
return_value["motions/workflow"] = {
1: {
@ -149,6 +241,14 @@ def all_data():
"first_state_id": 1,
}
}
return_value["motions/statute-paragraph"] = {
1: {
"id": 1,
"title": "§1 Preamble",
"text": "<p>Some preamble text</p>",
"weight": 10000,
}
}
return_value["motions/motion-change-recommendation"] = {}
return return_value
@ -162,9 +262,85 @@ def test_motion_slide(all_data):
"identifier": "4",
"title": "12345",
"text": "motion text",
"amendments": [
{
"id": 2,
"title": "Amendment for 12345",
"amendment_paragraphs": ["New motion text"],
"identifier": "Ä1",
"merge_amendment_into_final": 0,
}
],
"amendment_paragraphs": None,
"change_recommendations": [
{
"id": 2,
"motion_id": 1,
"rejected": False,
"internal": False,
"type": 0,
"other_description": "",
"line_from": 1,
"line_to": 2,
"text": "public new motion text",
"creation_time": "2019-02-09T09:54:06.256378+01:00",
}
],
"base_motion": None,
"base_statute": None,
"is_child": False,
"show_meta_box": True,
"reason": "",
"submitter": ["Administrator"],
"line_length": 90,
"line_numbering_mode": "none",
"preamble": "The assembly may decide:",
}
def test_amendment_slide(all_data):
element: Dict[str, Any] = {"id": 2}
data = projector.motion_slide(all_data, element)
assert data == {
"identifier": "Ä1",
"title": "Amendment for 12345",
"text": "",
"amendments": [],
"amendment_paragraphs": ["New motion text"],
"change_recommendations": [],
"base_motion": {"identifier": "4", "text": "motion text", "title": "12345"},
"base_statute": None,
"is_child": True,
"show_meta_box": True,
"reason": "",
"submitter": ["Administrator"],
"line_length": 90,
"line_numbering_mode": "none",
"preamble": "The assembly may decide:",
}
def test_statute_amendment_slide(all_data):
element: Dict[str, Any] = {"id": 3}
data = projector.motion_slide(all_data, element)
assert data == {
"identifier": None,
"title": "Statute amendment for §1 Preamble",
"text": "<p>Some other preamble text</p>",
"amendments": [],
"amendment_paragraphs": None,
"change_recommendations": [],
"base_motion": None,
"base_statute": {"title": "§1 Preamble", "text": "<p>Some preamble text</p>"},
"is_child": False,
"show_meta_box": True,
"reason": "",
"submitter": ["Administrator"],
"line_length": 90,
"line_numbering_mode": "none",
"preamble": "The assembly may decide:",
}