Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add backward linkage of story to the topic it belongs. #6855

Merged
merged 10 commits into from
Jun 14, 2019
Prev Previous commit
Next Next commit
Fix backend test issue.
  • Loading branch information
DubeySandeep committed Jun 12, 2019
commit 9eb87439b442458ba621c27c92475f277e28e8b5
5 changes: 4 additions & 1 deletion core/controllers/story_viewer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def setUp(self):
self.set_admins([self.ADMIN_USERNAME])
self.admin = user_services.UserActionsInfo(self.admin_id)
self.login(self.ADMIN_EMAIL)
self.TOPIC_ID = 'topic_id'
self.STORY_ID_1 = 'story_id_1'
self.NODE_ID_1 = 'node_1'
self.NODE_ID_2 = 'node_2'
Expand All @@ -49,8 +50,10 @@ def setUp(self):
self.EXP_ID, self.admin_id, title='Bridges in England',
category='Architecture', language_code='en')
rights_manager.publish_exploration(self.admin, self.EXP_ID)
self.save_new_topic(
self.TOPIC_ID, 'user', 'Topic', 'A new topic', [], [], [], [], 0)
story = story_domain.Story.create_default_story(
self.STORY_ID_1, 'Title')
self.STORY_ID_1, 'Title', self.TOPIC_ID)
story.description = ('Description')
self.node_1 = {
'id': self.NODE_ID_1,
Expand Down
4 changes: 2 additions & 2 deletions core/controllers/topic_viewer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def setUp(self):
self.topic_id_1 = 'topic1'

self.story = story_domain.Story.create_default_story(
self.story_id, 'story_title')
self.story_id, 'story_title', self.topic_id_1)
self.story.description = 'story_description'
story_services.save_new_story(self.admin_id, self.story)

self.topic = topic_domain.Topic.create_default_topic(
self.topic_id, 'public_topic_name')
Expand All @@ -51,6 +50,7 @@ def setUp(self):
self.topic.next_subtopic_id = 2
self.topic.canonical_story_ids.append(self.story_id)
topic_services.save_new_topic(self.admin_id, self.topic)
story_services.save_new_story(self.admin_id, self.story)

self.topic = topic_domain.Topic.create_default_topic(
self.topic_id_1, 'private_topic_name')
Expand Down
9 changes: 0 additions & 9 deletions core/domain/story_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,15 +630,6 @@ def validate(self):
raise utils.ValidationError(
'Invalid language code: %s' % self.language_code)

if not isinstance(self.belongs_to_topic, basestring):
raise utils.ValidationError(
'Expected belongs_to_topic should be a string, received: %s' % (
self.belongs_to_topic))

if len(self.belongs_to_topic) != 12:
raise utils.ValidationError('Invalid belongs_to_topic value: %s' % (
self.belongs_to_topic))

self.story_contents.validate()

@classmethod
Expand Down
3 changes: 3 additions & 0 deletions core/domain/story_jobs_one_off_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def setUp(self):
# Setup user who will own the test stories.
self.albert_id = self.get_user_id_from_email(self.ALBERT_EMAIL)
self.TOPIC_ID = topic_services.get_new_topic_id()
self.story_id_1 = 'story_id_1'
self.story_id_2 = 'story_id_2'
self.story_id_3 = 'story_id_3'
self.save_new_topic(
self.TOPIC_ID, self.albert_id, 'Name', 'Description',
[self.story_id_1, self.story_id_2], [self.story_id_3],
Expand Down
6 changes: 3 additions & 3 deletions core/domain/story_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,9 @@ def _save_story(committer_id, story, commit_message, change_list):

if story.id not in topic.canonical_story_ids + topic.additional_story_ids:
raise Exception(
'Expected story to belongs to the topic %s, but it is '
'neither a part of canonical story or the addition story of '
'the topic.' % story.belongs_to_topic)
'Expected story to belong to the topic %s, but it is '
'neither a part of the canonical stories or the additional stories '
'of the topic.' % story.belongs_to_topic)

story_model.description = story.description
story_model.title = story.title
Expand Down
2 changes: 1 addition & 1 deletion core/storage/story/gae_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class StoryModel(base_models.VersionedModel):
story_contents_schema_version = (
ndb.IntegerProperty(required=True, indexed=True))
# The topic id to which the story belongs.
belongs_to_topic = ndb.StringProperty(indexed=False, required=False)
belongs_to_topic = ndb.StringProperty(indexed=True, required=True)

def _trusted_commit(
self, committer_id, commit_type, commit_message, commit_cmds):
Expand Down