'Add k chapters, k^2 sections, k^3 verticals, k^4 problems to self.course (where k = branching)'

def populate_course(self, branching=2, emit_signals=False):

    user_id = self.user.id
    self.populated_usage_keys = {}
    def descend(parent, stack):
        if (not stack):
            return
        xblock_type = stack[0]
        for _ in range(branching):
            child = ItemFactory.create(category=xblock_type, parent_location=parent.location, user_id=user_id)
            self.populated_usage_keys.setdefault(xblock_type, []).append(child.location)
            descend(child, stack[1:])
    with self.store.bulk_operations(self.course.id, emit_signals=emit_signals):
        descend(self.course, ['chapter', 'sequential', 'vertical', 'problem'])
