def test_get_subtopic_page_contents_by_id(self): self.subtopic_page = subtopic_page_services.get_subtopic_page_by_id( self.TOPIC_ID, 1) recorded_voiceovers = { 'voiceovers_mapping': { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False, 'duration_secs': 7.213 } } } } expected_page_contents_dict = { 'subtitled_html': { 'content_id': 'content', 'html': '<p>hello world</p>' }, 'recorded_voiceovers': recorded_voiceovers, 'written_translations': { 'translations_mapping': { 'content': {} } } } self.subtopic_page.update_page_contents_html( state_domain.SubtitledHtml.from_dict({ 'html': '<p>hello world</p>', 'content_id': 'content' })) self.subtopic_page.update_page_contents_audio( state_domain.RecordedVoiceovers.from_dict(recorded_voiceovers)) subtopic_page_services.save_subtopic_page( self.user_id, self.subtopic_page, 'Updated page contents', [ subtopic_page_domain.SubtopicPageChange( { 'cmd': subtopic_page_domain.CMD_UPDATE_SUBTOPIC_PAGE_PROPERTY, 'subtopic_id': 1, 'property_name': 'page_contents_html', 'new_value': 'a', 'old_value': 'b' }) ]) subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( self.TOPIC_ID, 1)) self.assertEqual(subtopic_page_contents.to_dict(), expected_page_contents_dict) subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( self.TOPIC_ID, 2, strict=False)) self.assertEqual(subtopic_page_contents, None)
def test_get_subtopic_page_contents_by_id(self): self.subtopic_page = subtopic_page_services.get_subtopic_page_by_id( self.TOPIC_ID, 1) content_ids_to_audio_translations_dict = { 'content': { 'en': { 'filename': 'test.mp3', 'file_size_bytes': 100, 'needs_update': False } } } expected_page_contents_dict = { 'content_ids_to_audio_translations': content_ids_to_audio_translations_dict, 'subtitled_html': { 'content_id': 'content', 'html': 'hello world' }, 'written_translations': { 'translations_mapping': { 'content': {} } } } self.subtopic_page.update_page_contents_html({ 'html': 'hello world', 'content_id': 'content' }) self.subtopic_page.update_page_contents_audio( content_ids_to_audio_translations_dict) subtopic_page_services.save_subtopic_page( self.user_id, self.subtopic_page, 'Updated page contents', [ subtopic_page_domain.SubtopicPageChange( { 'cmd': subtopic_page_domain.CMD_UPDATE_SUBTOPIC_PAGE_PROPERTY, 'subtopic_id': 1, 'property_name': 'page_contents_html', 'new_value': 'a', 'old_value': 'b' }) ]) subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( self.TOPIC_ID, 1)) self.assertEqual(subtopic_page_contents.to_dict(), expected_page_contents_dict) subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( self.TOPIC_ID, 2, strict=False)) self.assertEqual(subtopic_page_contents, None)
def get(self, topic_name, subtopic_id): """Handles GET requests. Args: topic_name: str. The name of the topic that the subtopic is present in. subtopic_id: str. The id of the subtopic, which is an integer in string form. """ if not constants.ENABLE_NEW_STRUCTURE_PLAYERS: raise self.PageNotFoundException subtopic_id = int(subtopic_id) topic = topic_fetchers.get_topic_by_name(topic_name) next_subtopic_dict = None for index, subtopic in enumerate(topic.subtopics): if subtopic.id == subtopic_id: subtopic_title = subtopic.title if index != len(topic.subtopics) - 1: next_subtopic_dict = topic.subtopics[index + 1].to_dict() break subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( topic.id, subtopic_id)) subtopic_page_contents_dict = subtopic_page_contents.to_dict() self.values.update({ 'topic_id': topic.id, 'page_contents': subtopic_page_contents_dict, 'subtopic_title': subtopic_title, 'next_subtopic_dict': next_subtopic_dict }) self.render_json(self.values)
def get(self, topic_id, subtopic_id): """Handles GET requests.""" if not constants.ENABLE_NEW_STRUCTURE_PLAYERS: raise self.PageNotFoundException subtopic_id = int(subtopic_id) subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( topic_id, subtopic_id)) subtopic_page_contents_dict = subtopic_page_contents.to_dict() self.values.update({ 'topic_id': topic_id, 'subtopic_id': subtopic_id, 'page_contents': subtopic_page_contents_dict }) self.render_json(self.values)
def get(self, topic_name, subtopic_id): """Handles GET requests. Args: topic_name: str. The name of the topic that the subtopic is present in. subtopic_id: str. The id of the subtopic, which is an integer in string form. """ subtopic_id = int(subtopic_id) topic = topic_fetchers.get_topic_by_name(topic_name) next_subtopic_dict = None prev_subtopic_dict = None for index, subtopic in enumerate(topic.subtopics): if subtopic.id == subtopic_id: subtopic_title = subtopic.title if index != len(topic.subtopics) - 1: next_subtopic_dict = topic.subtopics[index + 1].to_dict() # Checking greater than 1 here, since otherwise the only # subtopic page of the topic would always link to itself at the # bottom of the subtopic page which isn't expected. elif len(topic.subtopics) > 1: prev_subtopic_dict = topic.subtopics[index - 1].to_dict() break subtopic_page_contents = ( subtopic_page_services.get_subtopic_page_contents_by_id( topic.id, subtopic_id)) subtopic_page_contents_dict = subtopic_page_contents.to_dict() self.values.update({ 'topic_id': topic.id, 'topic_name': topic.name, 'page_contents': subtopic_page_contents_dict, 'subtopic_title': subtopic_title, 'next_subtopic_dict': next_subtopic_dict, 'prev_subtopic_dict': prev_subtopic_dict, }) self.render_json(self.values)