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)
评论列表
文章目录