Example #1
0
    def test_reconstitute_excludes_deprecated_properties(self) -> None:
        exp_models.ExplorationRightsModel(
            id='id_0',
            owner_ids=['owner_id'],
            editor_ids=['editor_id'],
            voice_artist_ids=['voice_artist_id'],
            viewer_ids=['viewer_id'],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.0
        ).save(
            'cid', 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])
        saved_model = exp_models.ExplorationRightsModel.get('id_0')

        snapshot_dict = saved_model.compute_snapshot()
        snapshot_dict['translator_ids'] = ['owner_id']
        snapshot_dict['all_viewer_ids'] = []

        snapshot_dict = exp_models.ExplorationRightsModel.convert_to_valid_dict(
            snapshot_dict)

        exp_rights_model = exp_models.ExplorationRightsModel(**snapshot_dict)

        for field in ['translator_ids', 'all_viewer_ids']:
            self.assertNotIn(field, exp_rights_model._properties) # pylint: disable=protected-access
            self.assertNotIn(field, exp_rights_model._values) # pylint: disable=protected-access
Example #2
0
    def test_has_reference_to_user_id(self) -> None:
        exp_models.ExplorationRightsModel(
            id=self.EXP_ID_1,
            owner_ids=[self.USER_ID_1],
            editor_ids=[self.USER_ID_1],
            voice_artist_ids=[self.USER_ID_1],
            viewer_ids=[self.USER_ID_2],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.1
        ).save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])

        self.assertTrue(
            exp_models.ExplorationRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_1))
        self.assertTrue(
            exp_models.ExplorationRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_2))
        self.assertFalse(
            exp_models.ExplorationRightsSnapshotContentModel
            .has_reference_to_user_id(self.USER_ID_COMMITTER))
        self.assertFalse(
            exp_models.ExplorationRightsSnapshotContentModel
            .has_reference_to_user_id('x_id'))
Example #3
0
 def test_save(self) -> None:
     exp_models.ExplorationRightsModel(
         id='id_0',
         owner_ids=['owner_id'],
         editor_ids=['editor_id'],
         voice_artist_ids=['voice_artist_id'],
         viewer_ids=['viewer_id'],
         community_owned=False,
         status=constants.ACTIVITY_STATUS_PUBLIC,
         viewable_if_private=False,
         first_published_msec=0.0).save(
             'cid', 'Created new exploration right',
             [{
                 'cmd': rights_domain.CMD_CREATE_NEW
             }])
     saved_model = exp_models.ExplorationRightsModel.get('id_0')
     # Ruling out the possibility of None for mypy type checking.
     assert saved_model is not None
     self.assertEqual(saved_model.id, 'id_0')
     self.assertEqual(saved_model.owner_ids, ['owner_id'])
     self.assertEqual(saved_model.voice_artist_ids, ['voice_artist_id'])
     self.assertEqual(saved_model.viewer_ids, ['viewer_id'])
     self.assertEqual(
         ['editor_id', 'owner_id', 'viewer_id', 'voice_artist_id'],
         exp_models.ExplorationRightsSnapshotMetadataModel.get_by_id(
             'id_0-1').content_user_ids)
Example #4
0
    def setUp(self) -> None:
        super(ExplorationRightsModelRevertUnitTest, self).setUp()
        self.exploration_model = exp_models.ExplorationRightsModel(
            id=self.EXPLORATION_ID_1,
            owner_ids=[self.USER_ID_1],
            editor_ids=[],
            voice_artist_ids=[self.USER_ID_2],
            viewer_ids=[],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.4
        )
        self.exploration_model.save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}]
        )
        self.excluded_fields = ['created_on', 'last_updated', 'version']
        # Here copy.deepcopy is needed to mitigate
        # https://github.com/googlecloudplatform/datastore-ndb-python/issues/208
        self.original_dict = copy.deepcopy(
            self.exploration_model.to_dict(exclude=self.excluded_fields))
        self.exploration_model.owner_ids = [self.USER_ID_1, self.USER_ID_3]
        self.exploration_model.save(
            self.USER_ID_COMMITTER, 'Add owner',
            [{
                'cmd': rights_domain.CMD_CHANGE_ROLE,
                'assignee_id': self.USER_ID_3,
                'old_role': rights_domain.ROLE_NONE,
                'new_role': rights_domain.ROLE_OWNER
            }]
        )
        self.allow_revert_swap = self.swap(
            exp_models.ExplorationRightsModel, 'ALLOW_REVERT', True)

        exploration_rights_allowed_commands = copy.deepcopy(
            feconf.COLLECTION_RIGHTS_CHANGE_ALLOWED_COMMANDS)
        exploration_rights_allowed_commands.append({
            'name': feconf.CMD_REVERT_COMMIT,
            'required_attribute_names': [],
            'optional_attribute_names': [],
            'user_id_attribute_names': [],
            'allowed_values': {},
            'deprecated_values': {}
        })
        self.allowed_commands_swap = self.swap(
            feconf,
            'EXPLORATION_RIGHTS_CHANGE_ALLOWED_COMMANDS',
            exploration_rights_allowed_commands
        )
Example #5
0
    def setUp(self) -> None:
        super(ExplorationRightsModelUnitTest, self).setUp()
        user_models.UserSettingsModel(
            id=self.USER_ID_1,
            email='*****@*****.**',
            roles=[feconf.ROLE_ID_COLLECTION_EDITOR]
        ).put()
        user_models.UserSettingsModel(
            id=self.USER_ID_2,
            email='*****@*****.**',
            roles=[feconf.ROLE_ID_COLLECTION_EDITOR]
        ).put()
        exp_models.ExplorationRightsModel(
            id=self.EXPLORATION_ID_1,
            owner_ids=[self.USER_ID_1],
            editor_ids=[self.USER_ID_1],
            voice_artist_ids=[self.USER_ID_1],
            viewer_ids=[self.USER_ID_2],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.0
        ).save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])
        exp_models.ExplorationRightsModel(
            id=self.EXPLORATION_ID_2,
            owner_ids=[self.USER_ID_1],
            editor_ids=[self.USER_ID_1],
            voice_artist_ids=[self.USER_ID_1],
            viewer_ids=[self.USER_ID_1],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.0
        ).save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])
        exp_models.ExplorationRightsModel(
            id=self.EXPLORATION_ID_3,
            owner_ids=[self.USER_ID_1],
            editor_ids=[self.USER_ID_1],
            voice_artist_ids=[self.USER_ID_2],
            viewer_ids=[self.USER_ID_2],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.0
        ).save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])
        exp_models.ExplorationRightsModel(
            id=self.EXPLORATION_ID_4,
            owner_ids=[self.USER_ID_4],
            editor_ids=[self.USER_ID_4],
            voice_artist_ids=[self.USER_ID_4],
            viewer_ids=[self.USER_ID_4],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.4
        ).save(
            self.USER_ID_COMMITTER, 'Created new exploration right',
            [{'cmd': rights_domain.CMD_CREATE_NEW}])

        self.exp_1_dict = (
            exp_models.ExplorationRightsModel.get_by_id(
                self.EXPLORATION_ID_1).to_dict())