def test_build_path_with_invalid_location(self): path_finder = PathFinder(survey_json={}) blocks = [{ "group_id": 'first-valid-group-id', "group_instance": 0, "block": { "id": 'first-valid-block-id' } }, { "group_id": 'second-valid-group-id', "group_instance": 0, "block": { "id": 'second-valid-block-id' } }] invalid_group_location = Location( group_instance=0, group_id='this-group-id-doesnt-exist-in-the-list-of-blocks', block_id='first-valid-block-id') with self.assertRaises(StopIteration): path_finder.build_path(blocks, invalid_group_location) invalid_block_location = Location( group_instance=0, group_id='second-valid-group-id', block_id='this-block-id-doesnt-exist-in-the-list-of-blocks') with self.assertRaises(StopIteration): path_finder.build_path(blocks, invalid_block_location)
def test_build_path_with_invalid_location(self): path_finder = PathFinder(survey_json={}) blocks = [ { "group_id": 'first-valid-group-id', "group_instance": 0, "block": {"id": 'first-valid-block-id', 'type': 'questionnaire'} }, { "group_id": 'second-valid-group-id', "group_instance": 0, "block": {"id": 'second-valid-block-id', 'type': 'questionnaire'} } ] invalid_group_location = Location( group_instance=0, group_id='this-group-id-doesnt-exist-in-the-list-of-blocks', block_id='first-valid-block-id' ) self.assertEqual([], path_finder.build_path(blocks, invalid_group_location)) invalid_block_location = Location( group_instance=0, group_id='second-valid-group-id', block_id='this-block-id-doesnt-exist-in-the-list-of-blocks' ) self.assertEqual([], path_finder.build_path(blocks, invalid_block_location))
def test_route_based_on_answer_count(self): schema = load_schema_from_params('test', 'routing_answer_count') answer_group_id = 'first-name' answer_store = AnswerStore({}) answer_store.add(Answer( answer_id=answer_group_id, answer_instance=0, value='alice', )) answer_store.add(Answer( answer_id=answer_group_id, answer_instance=1, value='bob', )) completed_blocks = [ Location('multiple-questions-group', 0, 'household-composition') ] expected_next_location = Location('group-equal-2', 0, 'group-equal-2-block') should_not_be_present = Location('group-less-than-2', 0, 'group-less-than-2-block') path_finder = PathFinder(schema, answer_store, metadata={}, completed_blocks=completed_blocks) path = path_finder.build_path() self.assertNotIn(should_not_be_present, path) self.assertIn(expected_next_location, path)
def test_build_path_with_group_routing(self): # Given i have answered the routing question schema = load_schema_from_params('test', 'routing_group') schema.answer_is_in_repeating_group = MagicMock(return_value=False) answer_store = AnswerStore() answer_store.add(Answer(answer_id='which-group-answer', value='group2')) # When i build the path path_finder = PathFinder(schema, answer_store=answer_store, metadata={}, completed_blocks=[]) path = path_finder.build_path() # Then it should route me straight to Group2 and not Group1 self.assertNotIn(Location('group1', 0, 'group1-block'), path) self.assertIn(Location('group2', 0, 'group2-block'), path)