'Tests that an published unit with an unpublished draft remains published across export and re-import.'

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_vertical_with_draft_and_published_unit_has_changes_before_export_and_after_import(self, default_ms):

    with self._build_store(default_ms) as (contentstore, source_course_key):
        chapter = self.store.create_child(self.user_id, self.course.location, 'chapter', block_id='section_one')
        self.store.publish(chapter.location, self.user_id)
        sequential = self.store.create_child(self.user_id, chapter.location, 'sequential', block_id='subsection_one')
        self.store.publish(sequential.location, self.user_id)
        vertical = self.store.create_child(self.user_id, sequential.location, 'vertical', block_id='moon_unit')
        self.assertTrue(self._has_changes(vertical.location))
        self.store.publish(vertical.location, self.user_id)
        self.assertFalse(self._has_changes(vertical.location))
        unit = self.store.create_child(self.user_id, vertical.location, 'html', block_id='html_unit')
        self.assertTrue(self._has_changes(vertical.location))
        self.assertTrue(self._has_changes(unit.location))
        self.store.publish(vertical.location, self.user_id)
        self.assertFalse(self._has_changes(vertical.location))
        self.assertFalse(self._has_changes(unit.location))
        self.store.publish(unit.location, self.user_id)
        self.assertFalse(self._has_changes(vertical.location))
        self.assertFalse(self._has_changes(unit.location))
        self.store.publish(chapter.location, self.user_id)
        self.assertFalse(self._has_changes(chapter.location))
        self.assertFalse(self._has_changes(sequential.location))
        self.assertFalse(self._has_changes(vertical.location))
        self.assertFalse(self._has_changes(unit.location))
        component = self.store.get_item(unit.location)
        updated_display_name = 'Changed    Display    Name'
        component.display_name = updated_display_name
        component = self.store.update_item(component, self.user_id)
        self.assertTrue(self._has_changes(component.location))
        self._export_import_course_round_trip(self.store, contentstore, source_course_key, self.export_dir)
        self.assertTrue(self._has_changes(chapter.location))
        self.assertTrue(self._has_changes(sequential.location))
        self.assertTrue(self._has_changes(vertical.location))
        self.assertTrue(self._has_changes(unit.location))
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred, source_course_key):
            component = self.store.get_item(unit.location)
            self.assertEqual(component.display_name, updated_display_name)
        with self.store.branch_setting(ModuleStoreEnum.Branch.published_only, source_course_key):
            component = self.store.get_item(unit.location)
            self.assertEqual(component.display_name, 'Text')
