Ejemplo n.º 1
0
 def test_reconstitute(self) -> None:
     collection_models.CollectionRightsModel(
         id='id',
         owner_ids=['owner_ids'],
         editor_ids=['editor_ids'],
         voice_artist_ids=['voice_artist_ids'],
         viewer_ids=['viewer_ids'],
         community_owned=False,
         status=constants.ACTIVITY_STATUS_PUBLIC,
         viewable_if_private=False,
         first_published_msec=0.0).save(
             self.USER_ID_COMMITTER, 'Created new collection',
             [{
                 'cmd': rights_domain.CMD_CREATE_NEW
             }])
     collection_rights_model = (
         collection_models.CollectionRightsModel.get('id'))
     # Ruling out the possibility of None for mypy type checking.
     assert collection_rights_model is not None
     snapshot_dict = collection_rights_model.compute_snapshot()
     snapshot_dict['translator_ids'] = ['tid1', 'tid2']
     snapshot_dict = collection_rights_model.convert_to_valid_dict(
         snapshot_dict)
     collection_rights_model = collection_models.CollectionRightsModel(
         **snapshot_dict)
     self.assertNotIn('translator_ids', collection_rights_model._properties)  # pylint: disable=protected-access
     self.assertNotIn('translator_ids', collection_rights_model._values)  # pylint: disable=protected-access
Ejemplo n.º 2
0
    def test_has_reference_to_user_id(self) -> None:
        collection_models.CollectionRightsModel(
            id=self.COLLECTION_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 collection right',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])

        self.assertTrue(
            collection_models.CollectionRightsSnapshotContentModel.
            has_reference_to_user_id(self.USER_ID_1))
        self.assertTrue(
            collection_models.CollectionRightsSnapshotContentModel.
            has_reference_to_user_id(self.USER_ID_2))
        self.assertFalse(
            collection_models.CollectionRightsSnapshotContentModel.
            has_reference_to_user_id(self.USER_ID_COMMITTER))
        self.assertFalse(
            collection_models.CollectionRightsSnapshotContentModel.
            has_reference_to_user_id('x_id'))
Ejemplo n.º 3
0
    def test_save(self):
        # type: () -> None
        collection_models.CollectionRightsModel(
            id='id',
            owner_ids=['owner_ids'],
            editor_ids=['editor_ids'],
            voice_artist_ids=['voice_artist_ids'],
            viewer_ids=['viewer_ids'],
            community_owned=False,
            status=constants.ACTIVITY_STATUS_PUBLIC,
            viewable_if_private=False,
            first_published_msec=0.0).save(
                self.USER_ID_COMMITTER, 'Created new collection',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])
        collection_model = collection_models.CollectionRightsModel.get('id')
        # Ruling out the possibility of None for mypy type checking.
        assert collection_model is not None

        self.assertEqual('id', collection_model.id)
        self.assertEqual(
            ['editor_ids', 'owner_ids', 'viewer_ids', 'voice_artist_ids'],
            collection_models.CollectionRightsSnapshotMetadataModel.get_by_id(
                'id-1').content_user_ids)
Ejemplo n.º 4
0
    def setUp(self) -> None:
        super(CollectionRightsModelRevertUnitTest, self).setUp()
        self.collection_model = collection_models.CollectionRightsModel(
            id=self.COLLECTION_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.collection_model.save(
            self.USER_ID_COMMITTER, 'Created new collection 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.collection_model.to_dict(exclude=self.excluded_fields))
        self.collection_model.owner_ids = [self.USER_ID_1, self.USER_ID_3]
        self.collection_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(
            collection_models.CollectionRightsModel, 'ALLOW_REVERT', True)

        collection_rights_allowed_commands = copy.deepcopy(
            feconf.COLLECTION_RIGHTS_CHANGE_ALLOWED_COMMANDS)
        collection_rights_allowed_commands.append({
            'name': feconf.CMD_REVERT_COMMIT,
            'required_attribute_names': [],
            'optional_attribute_names': [],
            'user_id_attribute_names': []
        })
        self.allowed_commands_swap = self.swap(
            feconf,
            'COLLECTION_RIGHTS_CHANGE_ALLOWED_COMMANDS',
            collection_rights_allowed_commands
        )
Ejemplo n.º 5
0
    def setUp(self) -> None:
        super(CollectionRightsModelUnitTest,
              self).setUp()  # type: ignore[no-untyped-call]
        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()
        collection_models.CollectionRightsModel(
            id=self.COLLECTION_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 collection right',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])
        collection_models.CollectionRightsModel(
            id=self.COLLECTION_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.2).save(
                self.USER_ID_COMMITTER, 'Created new collection right',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])
        collection_models.CollectionRightsModel(
            id=self.COLLECTION_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.3).save(
                self.USER_ID_COMMITTER, 'Created new collection right',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])
        collection_models.CollectionRightsModel(
            id=self.COLLECTION_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 collection right',
                [{
                    'cmd': rights_domain.CMD_CREATE_NEW
                }])

        self.col_1_dict = (collection_models.CollectionRightsModel.get_by_id(
            self.COLLECTION_ID_1).to_dict())