コード例 #1
0
 def setUp(self) -> None:
     super(TopicRightsModelUnitTests, self).setUp()
     topic_models.TopicRightsModel(
         id=self.TOPIC_4_ID,
         manager_ids=[self.USER_ID_2],
         topic_is_published=True).commit(
             'commiter_id', 'New topic rights',
             [{
                 'cmd': topic_domain.CMD_CREATE_NEW
             }])
     topic_models.TopicRightsModel(
         id=self.TOPIC_5_ID,
         manager_ids=[self.USER_ID_2],
         topic_is_published=True).commit(
             'commiter_id', 'New topic rights',
             [{
                 'cmd': topic_domain.CMD_CREATE_NEW
             }])
コード例 #2
0
 def test_has_reference_to_user_id(self) -> None:
     with self.swap(base_models, 'FETCH_BATCH_SIZE', 1):
         topic_rights = topic_models.TopicRightsModel(
             id=self.TOPIC_1_ID, manager_ids=['manager_id'])
         topic_rights.commit('committer_id', 'New topic rights',
                             [{
                                 'cmd': topic_domain.CMD_CREATE_NEW
                             }])
         self.assertTrue(
             topic_models.TopicRightsModel.has_reference_to_user_id(
                 'manager_id'))
         self.assertFalse(
             topic_models.TopicRightsModel.has_reference_to_user_id('x_id'))
コード例 #3
0
ファイル: gae_models_test.py プロジェクト: sajalasati/oppia
    def test_that_subsidiary_models_are_created_when_new_model_is_saved(
            self
    ) -> None:
        """Tests the _trusted_commit() method."""

        topic_rights = topic_models.TopicRightsModel(
            id=self.TOPIC_ID,
            manager_ids=[],
            topic_is_published=True
        )
        # Topic is created but not committed/saved.
        topic = topic_models.TopicModel(
            id=self.TOPIC_ID,
            name=self.TOPIC_NAME,
            abbreviated_name='abbrev',
            url_fragment='url-fragment',
            description='description',
            canonical_name=self.TOPIC_CANONICAL_NAME,
            subtopic_schema_version=feconf.CURRENT_SUBTOPIC_SCHEMA_VERSION,
            story_reference_schema_version=(
                feconf.CURRENT_STORY_REFERENCE_SCHEMA_VERSION),
            next_subtopic_id=1,
            language_code='en'
        )
        # We check that topic has not been saved before calling commit().
        self.assertIsNone(topic_models.TopicModel.get_by_name(self.TOPIC_NAME))
        # We call commit() expecting that _trusted_commit works fine
        # and saves topic to datastore.
        topic_rights.commit(
            committer_id=feconf.SYSTEM_COMMITTER_ID,
            commit_message='Created new topic rights',
            commit_cmds=[{'cmd': topic_domain.CMD_CREATE_NEW}]
        )
        topic.commit(
            committer_id=feconf.SYSTEM_COMMITTER_ID,
            commit_message='Created new topic',
            commit_cmds=[{'cmd': topic_domain.CMD_CREATE_NEW}]
        )
        # Now we check that topic is not None and that actually
        # now topic exists, that means that commit() worked fine.
        self.assertIsNotNone(
            topic_models.TopicModel.get_by_name(self.TOPIC_NAME)
        )
コード例 #4
0
ファイル: gae_models_test.py プロジェクト: sajalasati/oppia
    def test_has_reference_to_user_id(self) -> None:
        topic_models.TopicRightsModel(
            id=self.TOPIC_ID_1,
            manager_ids=[self.USER_ID_1, self.USER_ID_2],
        ).commit(
            self.USER_ID_COMMITTER, 'Created new topic right',
            [{'cmd': topic_domain.CMD_CREATE_NEW}])

        self.assertTrue(
            topic_models.TopicRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_1))
        self.assertTrue(
            topic_models.TopicRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_2))
        self.assertFalse(
            topic_models.TopicRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_COMMITTER))
        self.assertFalse(
            topic_models.TopicRightsSnapshotContentModel
            .has_reference_to_user_id('x_id'))