'Tests that course_overview tabs deletion is correctly rolled back if an Exception
occurs while updating the course_overview.'

@ddt.data(ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split)
def test_tabs_deletion_rollback_on_integrity_error(self, modulestore_type):

    course = CourseFactory.create(default_store=modulestore_type)
    course_overview = CourseOverview.get_from_id(course.id)
    expected_tabs = {tab.tab_id for tab in course_overview.tabs.all()}
    with mock.patch('openedx.core.djangoapps.content.course_overviews.models.CourseOverviewTab.objects.bulk_create') as course_overview_tabs_bulk_create:
        course_overview_tabs_bulk_create.side_effect = IntegrityError
        course.display_name = u'Updated    display    name'
        with self.store.branch_setting(ModuleStoreEnum.Branch.draft_preferred):
            self.store.update_item(course, ModuleStoreEnum.UserID.test)
        actual_tabs = {tab.tab_id for tab in course_overview.tabs.all()}
        self.assertEqual(actual_tabs, expected_tabs)
        self.assertNotEqual(course_overview.display_name, course.display_name)
