def test_get_subtopic_page_from_model(self): subtopic_page_model = topic_models.SubtopicPageModel.get( self.subtopic_page_id) subtopic_page = subtopic_page_services.get_subtopic_page_from_model( subtopic_page_model) self.assertEqual(subtopic_page.to_dict(), self.subtopic_page.to_dict())
def _get_model_domain_object_instance(cls, item): return subtopic_page_services.get_subtopic_page_from_model(item)
def test_migrate_page_contents_from_v3_to_v4_schema(self): current_schema_version_swap = self.swap( feconf, 'CURRENT_SUBTOPIC_PAGE_CONTENTS_SCHEMA_VERSION', 4) expected_html_content = ('<p>1 × 3 😕 😊</p>') html_content = ('<p>1 × 3 😕 😊</p>') written_translations_dict = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } written_translations_dict_math = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': expected_html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } recorded_voiceovers = { 'voiceovers_mapping': { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False, 'duration_secs': 7.213 } } } } page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict } expected_page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': expected_html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict_math } subtopic_page_id = subtopic_models.SubtopicPageModel.get_new_id('') subtopic_page_model = subtopic_models.SubtopicPageModel( id=subtopic_page_id, topic_id=self.TOPIC_ID, page_contents=page_contents_dict, page_contents_schema_version=3, language_code='en') self.assertEqual(subtopic_page_model.page_contents_schema_version, 3) with current_schema_version_swap: subtopic_page = subtopic_page_services.get_subtopic_page_from_model( subtopic_page_model) self.assertEqual(subtopic_page.page_contents_schema_version, 4) self.assertEqual(subtopic_page.page_contents.to_dict(), expected_page_contents_dict)
def test_migrate_page_contents_to_latest_schema(self): current_schema_version_swap = self.swap( feconf, 'CURRENT_SUBTOPIC_PAGE_CONTENTS_SCHEMA_VERSION', 2) html_content = ( '<p>Value</p><oppia-noninteractive-math raw_latex-with-value="&a' 'mp;quot;+,-,-,+&quot;"></oppia-noninteractive-math>') expected_html_content = ( '<p>Value</p><oppia-noninteractive-math math_content-with-value=' '"{&quot;raw_latex&quot;: &quot;+,-,-,+&quot;, &' 'amp;quot;svg_filename&quot;: &quot;&quot;}"></oppia' '-noninteractive-math>') written_translations_dict = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } written_translations_dict_math = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': expected_html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } recorded_voiceovers = { 'voiceovers_mapping': { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False, 'duration_secs': 7.213 } } } } page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict } expected_page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': expected_html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict_math } subtopic_page_id = topic_models.SubtopicPageModel.get_new_id('') subtopic_page_model = topic_models.SubtopicPageModel( id=subtopic_page_id, topic_id=self.TOPIC_ID, page_contents=page_contents_dict, page_contents_schema_version=1, language_code='en') self.assertEqual(subtopic_page_model.page_contents_schema_version, 1) with current_schema_version_swap: subtopic_page = subtopic_page_services.get_subtopic_page_from_model( subtopic_page_model) self.assertEqual(subtopic_page.page_contents_schema_version, 2) self.assertEqual(subtopic_page.page_contents.to_dict(), expected_page_contents_dict)
def test_migrate_page_contents_from_v2_to_v3_schema(self): current_schema_version_swap = self.swap( feconf, 'CURRENT_SUBTOPIC_PAGE_CONTENTS_SCHEMA_VERSION', 3) html_content = ('<oppia-noninteractive-svgdiagram ' 'svg_filename-with-value=""img1.svg""' ' alt-with-value=""Image"">' '</oppia-noninteractive-svgdiagram>') expected_html_content = ( '<oppia-noninteractive-image alt-with-value=\'\"Image\"\'' ' caption-with-value="&quot;&quot;" ' 'filepath-with-value=\'\"img1.svg\"\'>' '</oppia-noninteractive-image>') written_translations_dict = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } written_translations_dict_math = { 'translations_mapping': { 'content1': { 'en': { 'data_format': 'html', 'translation': expected_html_content, 'needs_update': True }, 'hi': { 'data_format': 'html', 'translation': 'Hey!', 'needs_update': False } }, 'feedback_1': { 'hi': { 'data_format': 'html', 'translation': 'Testing!', 'needs_update': False }, 'en': { 'data_format': 'html', 'translation': 'hello!', 'needs_update': False } } } } recorded_voiceovers = { 'voiceovers_mapping': { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False, 'duration_secs': 7.213 } } } } page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict } expected_page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': expected_html_content }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': written_translations_dict_math } subtopic_page_id = subtopic_models.SubtopicPageModel.get_new_id('') subtopic_page_model = subtopic_models.SubtopicPageModel( id=subtopic_page_id, topic_id=self.TOPIC_ID, page_contents=page_contents_dict, page_contents_schema_version=2, language_code='en') self.assertEqual(subtopic_page_model.page_contents_schema_version, 2) with current_schema_version_swap: subtopic_page = subtopic_page_services.get_subtopic_page_from_model( subtopic_page_model) self.assertEqual(subtopic_page.page_contents_schema_version, 3) self.assertEqual(subtopic_page.page_contents.to_dict(), expected_page_contents_dict)