[IMP] survey_extra_fields, survey_base : modifications to make them work in v18

This commit is contained in:
2026-06-10 16:56:56 +02:00
parent 8f235646ef
commit 9d1cd2746a
10 changed files with 194 additions and 182 deletions

View File

@@ -46,14 +46,14 @@ class TestSurveyFileCommon(common.TestSurveyCommon):
class TestSurveyFileSaveLines(TestSurveyFileCommon):
"""Test the save_lines method for file question type."""
"""Test the _save_lines method for file question type."""
def test_save_file_answer(self):
"""Submitting a file stores base64 data and filename."""
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": self.file_name})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
@@ -68,7 +68,7 @@ class TestSurveyFileSaveLines(TestSurveyFileCommon):
"""Submitting empty answer marks the line as skipped."""
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
answer.save_lines(self.question_file, "")
answer._save_lines(self.question_file, "")
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
@@ -81,11 +81,11 @@ class TestSurveyFileSaveLines(TestSurveyFileCommon):
"""Submitting a new file updates the existing answer line."""
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json_1 = json.dumps({"data": self.file_b64, "name": "first.pdf"})
answer.save_lines(self.question_file, file_json_1)
answer._save_lines(self.question_file, file_json_1)
new_b64 = base64.b64encode(b"Updated content").decode()
file_json_2 = json.dumps({"data": new_b64, "name": "second.pdf"})
answer.save_lines(self.question_file, file_json_2)
answer._save_lines(self.question_file, file_json_2)
lines = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
@@ -98,9 +98,9 @@ class TestSurveyFileSaveLines(TestSurveyFileCommon):
"""Uploading a file then submitting empty marks line as skipped."""
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": self.file_name})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
answer.save_lines(self.question_file, "")
answer._save_lines(self.question_file, "")
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
@@ -117,7 +117,7 @@ class TestSurveyFileConstraints(TestSurveyFileCommon):
self.question_file.write({"max_file_size": 0, "allowed_extensions": False})
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": "anything.exe"})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
)
@@ -128,7 +128,7 @@ class TestSurveyFileConstraints(TestSurveyFileCommon):
self.question_file.write({"max_file_size": 10})
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": self.file_name})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
)
@@ -142,14 +142,14 @@ class TestSurveyFileConstraints(TestSurveyFileCommon):
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": large_b64, "name": self.file_name})
with self.assertRaises(Exception):
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
def test_allowed_extension_passes(self):
"""File with an allowed extension passes."""
self.question_file.write({"allowed_extensions": ".pdf,.docx"})
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": "report.docx"})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
)
@@ -161,14 +161,14 @@ class TestSurveyFileConstraints(TestSurveyFileCommon):
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": "script.exe"})
with self.assertRaises(Exception):
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
def test_both_constraints_valid(self):
"""File respecting both size and extension constraints passes."""
self.question_file.write({"max_file_size": 10, "allowed_extensions": ".pdf"})
answer = self._add_answer(self.survey, self.survey_manager.partner_id)
file_json = json.dumps({"data": self.file_b64, "name": self.file_name})
answer.save_lines(self.question_file, file_json)
answer._save_lines(self.question_file, file_json)
line = answer.user_input_line_ids.filtered(
lambda l: l.question_id == self.question_file
)