'Creates a graded homework section within a chapter and returns the section.'

def add_graded_section_to_course(self, name, section_format='Homework', late=False, reset=False, showanswer=False):

    if (not hasattr(self, 'chapter')):
        self.chapter = ItemFactory.create(parent_location=self.course.location, category='chapter')
    if late:
        section = ItemFactory.create(parent_location=self.chapter.location, display_name=name, category='sequential', metadata={'graded': True, 'format': section_format, 'due': '2013-05-20T23:30'})
    elif reset:
        section = ItemFactory.create(parent_location=self.chapter.location, display_name=name, category='sequential', rerandomize='always', metadata={'graded': True, 'format': section_format})
    elif showanswer:
        section = ItemFactory.create(parent_location=self.chapter.location, display_name=name, category='sequential', showanswer='never', metadata={'graded': True, 'format': section_format})
    else:
        section = ItemFactory.create(parent_location=self.chapter.location, display_name=name, category='sequential', metadata={'graded': True, 'format': section_format})
    self.refresh_course()
    return section
