def test_story_model(self) -> None: """Method to test the StoryModel.""" committer_id = 'test_committer_id' commit_message = 'test_commit_message' commit_cmds = [{'cmd': 'test_command'}] story_instance = story_models.StoryModel( id='id', title='title', description='description', notes='notes', story_contents_schema_version=( feconf.CURRENT_STORY_CONTENTS_SCHEMA_VERSION), corresponding_topic_id='topic_id', language_code='language_code', url_fragment='title') story_instance.commit(committer_id, commit_message, commit_cmds) story_by_id = story_models.StoryModel.get_by_id('id') self.assertEqual(story_by_id.description, 'description') self.assertEqual(story_by_id.id, 'id') self.assertEqual(story_by_id.notes, 'notes') self.assertEqual(story_by_id.language_code, 'language_code') self.assertEqual(story_by_id.title, 'title') self.assertEqual(story_by_id.url_fragment, 'title')
def test_get_by_url_fragment(self) -> None: committer_id = 'test_committer_id' commit_message = 'test_commit_message' commit_cmds = [{'cmd': 'test_command'}] story_instance = story_models.StoryModel( id='id', title='title', description='description', notes='notes', story_contents_schema_version=( feconf.CURRENT_STORY_CONTENTS_SCHEMA_VERSION), corresponding_topic_id='topic_id', language_code='language_code', url_fragment='unique-url') story_instance.commit(committer_id, commit_message, commit_cmds) story_by_id = story_models.StoryModel.get_by_url_fragment('unique-url') # Ruling out the possibility of None for mypy type checking. assert story_by_id is not None self.assertEqual(story_by_id.description, 'description') self.assertEqual(story_by_id.id, 'id') self.assertEqual(story_by_id.notes, 'notes') self.assertEqual(story_by_id.language_code, 'language_code') self.assertEqual(story_by_id.title, 'title') self.assertEqual(story_by_id.url_fragment, 'unique-url')
def _create_story(committer_id, story, commit_message, commit_cmds): """Creates a new story. Args: committer_id: str. ID of the committer. story: Story. The story domain object. commit_message: str. A description of changes made to the story. commit_cmds: list(StoryChange). A list of change commands made to the given story. """ story.validate() model = story_models.StoryModel( id=story.id, description=story.description, title=story.title, thumbnail_bg_color=story.thumbnail_bg_color, thumbnail_filename=story.thumbnail_filename, thumbnail_size_in_bytes=story.thumbnail_size_in_bytes, language_code=story.language_code, story_contents_schema_version=story.story_contents_schema_version, notes=story.notes, story_contents=story.story_contents.to_dict(), corresponding_topic_id=story.corresponding_topic_id, url_fragment=story.url_fragment, meta_tag_content=story.meta_tag_content ) commit_cmd_dicts = [commit_cmd.to_dict() for commit_cmd in commit_cmds] model.commit(committer_id, commit_message, commit_cmd_dicts) story.version += 1 create_story_summary(story.id)