def _build_blocks(group_schema, path, answer_store, metadata, schema, group_instance): blocks = [] block_ids_on_path = [location.block_id for location in path if location.group_id == group_schema['id'] and location.group_instance == group_instance] for block in group_schema['blocks']: if block['id'] in block_ids_on_path and \ block['type'] == 'Question': blocks.extend([Block(block, group_schema['id'], answer_store, metadata, schema, group_instance).serialize()]) return blocks
def _build_blocks(group_schema, answers, path, metadata, url_for): blocks = [] for block in group_schema['blocks']: if block['id'] in [location.block_id for location in path] and \ block['type'] == 'Questionnaire': blocks.extend([ Block(block, answers, group_schema['id'], metadata, url_for) ]) return blocks
def test_create_block(self): # Given block_schema = build_block_schema([{'id': 'mock_question_schema'}]) # When with patch('app.templating.summary.block.Question', return_value=get_mock_question('A Question')), \ patch('app.templating.summary.block.evaluate_skip_conditions', return_value=False), \ patch('app.templating.summary.block.url_for', return_value='http://a.url/'): block = Block(block_schema, 'group_id', self.answer_store, self.metadata, self.schema) # Then self.assertEqual(block.id, 'block_id') self.assertEqual(block.title, 'A section title') self.assertEqual(block.number, '1') self.assertEqual(len(block.questions), 1) self.assertEqual(block.questions[0], 'A Question')
def test_create_section_with_multiple_questions(self): # Given block_schema = build_block_schema([{ 'id': 'mock_question_schema' }, { 'id': 'mock_question_schema' }]) # When with patch('app.templating.summary.block.Question', side_effect=[get_mock_question('A Question'), get_mock_question('A Second Question')]), \ patch('app.templating.summary.block.evaluate_skip_conditions', return_value=False), \ patch('app.templating.summary.block.url_for', return_value='http://a.url/'): block = Block(block_schema, 'group_id', self.answer_store, self.metadata, self.schema) # Then self.assertEqual(len(block.questions), 2) self.assertEqual(block.questions[0], 'A Question') self.assertEqual(block.questions[1], 'A Second Question')
def test_question_should_be_skipped(self): # Given block_schema = build_block_schema([{ 'id': 'mock_question_schema', 'skip_conditions': 'mocked' }, { 'id': 'mock_question_schema' }]) with patch('app.templating.summary.block.Question', side_effect=[get_mock_question('A Second Question')]) as patched_question_context, \ patch('app.templating.summary.block.evaluate_skip_conditions', side_effect=[False, True]), \ patch('app.templating.summary.block.url_for', return_value='http://a.url/'): # When block = Block(block_schema, 'group_id', self.answer_store, self.metadata, self.schema) # Then patched_question_context.assert_called_once() self.assertTrue(len(block.questions) == 1) self.assertEqual(block.questions[0], 'A Second Question')