test_fields.py 文件源码

python
阅读 37 收藏 0 点赞 0 评论 0

项目:eq-survey-runner 作者: ONSdigital 项目源码 文件源码
def test_radio_field(self):
        radio_json = {
            "guidance": "",
            "id": "choose-your-side-answer",
            "label": "Choose a side",
            "mandatory": True,
            "options": [
                {
                    "label": "Light Side",
                    "value": "Light Side",
                    "description": "The light side of the Force"
                },
                {
                    "label": "Dark Side",
                    "value": "Dark Side",
                    "description": "The dark side of the Force"
                },
                {
                    "label": "I prefer Star Trek",
                    "value": "I prefer Star Trek"
                },
                {
                    "label": "Other",
                    "value": "Other"
                }
            ],
            "q_code": "20",
            "type": "Radio"
        }

        unbound_field = get_field(radio_json, radio_json['label'], error_messages, self.answer_store)

        expected_choices = [(option['label'], option['value']) for option in radio_json['options']]

        self.assertTrue(unbound_field.field_class == SelectField)
        self.assertTrue(unbound_field.kwargs['coerce'], _coerce_str_unless_none)
        self.assertEquals(unbound_field.kwargs['label'], radio_json['label'])
        self.assertEquals(unbound_field.kwargs['description'], radio_json['guidance'])
        self.assertEquals(unbound_field.kwargs['choices'], expected_choices)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号