'Test for calling get_preview_html. Ensures data-usage-id is correctly set and
asides are correctly included.'

@XBlockAside.register_temp_plugin(AsideTestType, 'test_aside')
def test_preview_fragment(self):

    course = CourseFactory.create(default_store=ModuleStoreEnum.Type.split)
    html = ItemFactory.create(parent_location=course.location, category='html', data={'data': '<html>foobar</html>'})
    config = StudioConfig.current()
    config.enabled = True
    config.save()
    request = RequestFactory().get('/dummy-url')
    request.user = UserFactory()
    request.session = {}
    context = {'reorderable_items': set(), 'read_only': True}
    html = get_preview_fragment(request, html, context).content
    html_pattern = re.escape(unicode(course.id.make_usage_key('html', 'replaceme'))).replace('replaceme', 'html_[0-9]*')
    self.assertRegexpMatches(html, 'data-usage-id="{}"'.format(html_pattern))
    self.assertRegexpMatches(html, '<html>foobar</html>')
    self.assertRegexpMatches(html, 'data-block-type=[\\"\\\']test_aside[\\"\\\']')
    self.assertRegexpMatches(html, 'Aside    rendered')
    self.assertNotRegexpMatches(html, 'data-block-type=[\\"\\\']acid_aside[\\"\\\']')
    about = modulestore().get_item(course.id.make_usage_key('about', 'overview'))
    html = get_preview_fragment(request, about, context).content
    self.assertNotRegexpMatches(html, 'data-block-type=[\\"\\\']test_aside[\\"\\\']')
    self.assertNotRegexpMatches(html, 'Aside    rendered')
