def _get_fields(connection: Connection, question: RowProxy) -> dict: """ Extract the relevant fields from a record in the question table. :param connection: a SQLAlchemy Connection :param question: A RowProxy for a record in the question table. :return: A dictionary of the fields. """ result = {'question_id': question.question_id, 'question_title': question.question_title, 'hint': question.hint, 'sequence_number': question.sequence_number, 'question_to_sequence_number': question.question_to_sequence_number, 'allow_multiple': question.allow_multiple, 'type_constraint_name': question.type_constraint_name, 'logic': question.logic} if question.type_constraint_name == 'multiple_choice': choices = get_choices(connection, question.question_id) result['choices'] = [_get_choice_fields(choice) for choice in choices] branches = get_branches(connection, question.question_id) if branches.rowcount > 0: result['branches'] = [_get_branch_fields(brn) for brn in branches] return result
def testGetBranches(self): q_where = question_table.select().where( question_table.c.type_constraint_name == 'multiple_choice') question_id = connection.execute(q_where).first().question_id branches = get_branches(connection, question_id) self.assertGreater(branches.rowcount, 0)