You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dianshang-houduan/tools/test_repair_remaining_step_...

39 lines
2.1 KiB
Python

import json
import unittest
from repair_remaining_step_answers import plan_row, QUESTIONNAIRE_ROW
class RemainingStepMigrationTest(unittest.TestCase):
def test_moves_built_in_steps_and_preserves_custom_answers(self):
row = {'id': 'row', 'task_key': 'market-opportunity-selection', 'dynamic_step_answers':
json.dumps({'step5': {'reviewInsights': [1]}, 'step6': {'developmentConclusion': 'A'}, 'teacher-custom': {'url': '/file/custom.png'}})}
changes = plan_row(row)
self.assertEqual(json.loads(changes['step5_answer']), {'reviewInsights': [1]})
self.assertEqual(json.loads(changes['step6_answer']), {'developmentConclusion': 'A'})
self.assertEqual(json.loads(changes['dynamic_step_answers']), {'teacher-custom': {'url': '/file/custom.png'}})
self.assertFalse(plan_row({**row, **changes}))
def test_rejects_existing_different_column(self):
with self.assertRaises(ValueError):
plan_row({'id': 'row', 'task_key': 'product-pricing', 'step5_answer': '{"a":1}',
'dynamic_step_answers': '{"step5":{"a":2}}'})
def test_moves_only_duplicate_questionnaire_metadata(self):
row = {'id': QUESTIONNAIRE_ROW, 'task_key': 'consumer-behavior',
'step3_answer': '{"importedDocumentUrl":"/file/q.docx","questions":[1]}',
'step4_answer': '{"questionnaireFileUrl":"/file/q.docx","questionnaireFileName":"q.docx","dataExcelFileUrl":"/file/data.xlsx","rows":[2]}'}
changes = plan_row(row)
self.assertEqual(json.loads(changes['step3_answer'])['questions'], [1])
self.assertEqual(json.loads(changes['step4_answer']), {'dataExcelFileUrl': '/file/data.xlsx', 'rows': [2]})
self.assertFalse(plan_row({**row, **changes}))
def test_different_questionnaire_urls_abort(self):
with self.assertRaises(ValueError):
plan_row({'id': QUESTIONNAIRE_ROW, 'task_key': 'consumer-behavior',
'step3_answer': '{"importedDocumentUrl":"/file/one.docx"}',
'step4_answer': '{"questionnaireFileUrl":"/file/another.docx"}'})
if __name__ == '__main__':
unittest.main()