'Test if sources got from CDN'

@patch('xmodule.video_module.video_module.BrandingInfoConfig')
@patch('xmodule.video_module.video_module.rewrite_video_url')
def test_get_html_cdn_source(self, mocked_get_video, mock_BrandingInfoConfig):

    mock_BrandingInfoConfig.get_config.return_value = {'CN': {'url': 'http://www.xuetangx.com', 'logo_src': 'http://www.xuetangx.com/static/images/logo.png', 'logo_tag': 'Video    hosted    by    XuetangX.com'}}
    def side_effect(*args, **kwargs):
        cdn = {'http://example.com/example.mp4': 'http://cdn-example.com/example.mp4', 'http://example.com/example.webm': 'http://cdn-example.com/example.webm'}
        return cdn.get(args[1])
    mocked_get_video.side_effect = side_effect
    SOURCE_XML = '\n                                                <video    show_captions="true"\n                                                display_name="A    Name"\n                                                sub="a_sub_file.srt.sjson"    source="{source}"\n                                                download_video="{download_video}"\n                                                edx_video_id="{edx_video_id}"\n                                                start_time="01:00:03"    end_time="01:00:10"\n                                                >\n                                                                {sources}\n                                                </video>\n                                '
    case_data = {'download_video': 'true', 'source': 'example_source.mp4', 'sources': '\n                                                                <source    src="http://example.com/example.mp4"/>\n                                                                <source    src="http://example.com/example.webm"/>\n                                                ', 'result': {'download_video_link': u'example_source.mp4', 'sources': [u'http://cdn-example.com/example.mp4', u'http://cdn-example.com/example.webm']}}
    cases = [dict(case_data, edx_video_id=''), dict(case_data, edx_video_id='vid-v1:12345')]
    initial_context = {'branding_info': {'logo_src': 'http://www.xuetangx.com/static/images/logo.png', 'logo_tag': 'Video    hosted    by    XuetangX.com', 'url': 'http://www.xuetangx.com'}, 'license': None, 'bumper_metadata': 'null', 'cdn_eval': False, 'cdn_exp_group': None, 'display_name': u'A    Name', 'download_video_link': None, 'handout': None, 'id': None, 'metadata': self.default_metadata_dict, 'track': None, 'transcript_download_format': u'srt', 'transcript_download_formats_list': [{'display_name': 'SubRip    (.srt)    file', 'value': 'srt'}, {'display_name': 'Text    (.txt)    file', 'value': 'txt'}], 'poster': 'null'}
    for data in cases:
        DATA = SOURCE_XML.format(download_video=data['download_video'], source=data['source'], sources=data['sources'], edx_video_id=data['edx_video_id'])
        self.initialize_module(data=DATA)
        self.item_descriptor.xmodule_runtime.user_location = 'CN'
        context = self.item_descriptor.render('student_view').content
        expected_context = dict(initial_context)
        expected_context['metadata'].update({'transcriptTranslationUrl': self.item_descriptor.xmodule_runtime.handler_url(self.item_descriptor, 'transcript', 'translation/__lang__').rstrip('/?'), 'transcriptAvailableTranslationsUrl': self.item_descriptor.xmodule_runtime.handler_url(self.item_descriptor, 'transcript', 'available_translations').rstrip('/?'), 'saveStateUrl': (self.item_descriptor.xmodule_runtime.ajax_url + '/save_user_state'), 'sources': data['result'].get('sources', [])})
        expected_context.update({'id': self.item_descriptor.location.html_id(), 'download_video_link': data['result'].get('download_video_link'), 'metadata': json.dumps(expected_context['metadata'])})
        self.assertEqual(context, self.item_descriptor.xmodule_runtime.render_template('video.html', expected_context))
