'Ensures that a unit with the given state is present on the course outline'

def _ensure_unit_present(self, unit_state):

    if (unit_state.publish_state == self.PublishState.PUBLISHED):
        return
    name = unit_state.name
    self.course_outline_page.visit()
    subsection = self.course_outline_page.section(name).subsection(name)
    subsection.expand_subsection()
    if (unit_state.publish_state == self.PublishState.UNPUBLISHED_CHANGES):
        unit = subsection.unit(name).go_to()
        add_discussion(unit)
    elif (unit_state.publish_state == self.PublishState.NEVER_PUBLISHED):
        subsection.add_unit()
        unit = ContainerPage(self.browser, None)
        unit.wait_for_page()
    if (unit.is_staff_locked != unit_state.is_locked):
        unit.toggle_staff_lock()
