'What happens when everything works like we expect it to.
If `create_after_overview` is True, we will temporarily disable
thumbnail creation so that the initial CourseOverview is created without
an image_set, and the CourseOverviewImageSet is created afterwards. If
`create_after_overview` is False, we\'ll create the CourseOverviewImageSet
at the same time as the CourseOverview.'

@ddt.data(*itertools.product([ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split], [True, False]))
@ddt.unpack
def test_happy_path(self, modulestore_type, create_after_overview):

    image = Image.new('RGB', (800, 400), 'blue')
    image_buff = StringIO()
    image.save(image_buff, format='JPEG')
    image_buff.seek(0)
    image_name = 'big_course_image.jpeg'
    with self.store.default_store(modulestore_type):
        course = CourseFactory.create(default_store=modulestore_type, course_image=image_name)
        course_image_asset_key = StaticContent.compute_location(course.id, course.course_image)
        course_image_content = StaticContent(course_image_asset_key, image_name, 'image/jpeg', image_buff)
        contentstore().save(course_image_content)
        if create_after_overview:
            self.set_config(enabled=False)
        course_overview = CourseOverview.get_from_id(course.id)
        if create_after_overview:
            self.assertFalse(hasattr(course_overview, 'image_set'))
            self.set_config(enabled=True)
            course_overview = CourseOverview.get_from_id(course.id)
        self.assertTrue(hasattr(course_overview, 'image_set'))
        image_urls = course_overview.image_urls
        config = CourseOverviewImageConfig.current()
        self.assertTrue(image_urls['raw'].endswith('big_course_image.jpeg'))
        self.assertTrue(image_urls['small'].endswith('big_course_image-jpeg-{}x{}.jpg'.format(*config.small)))
        self.assertTrue(image_urls['large'].endswith('big_course_image-jpeg-{}x{}.jpg'.format(*config.large)))
        for (image_url, expected_size) in [(image_urls['small'], config.small), (image_urls['large'], config.large)]:
            image_key = StaticContent.get_location_from_path(image_url)
            image_content = AssetManager.find(image_key)
            image = Image.open(StringIO(image_content.data))
            self.assertEqual(image.size, expected_size)
