def test_add_content_user_ids_to_multiple_rights_snapshots(self):
    with self.collection_rights_model_swap:
        collection_model = collection_models.CollectionRightsModel(id=self.COL_1_ID, owner_ids=[self.USER_1_ID], editor_ids=[], voice_artist_ids=[], viewer_ids=[], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.0)
        collection_model.save('cid', 'Created new collection rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        collection_model.editor_ids = [self.USER_1_ID, self.USER_4_ID]
        collection_model.save('cid', 'Add editors', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_4_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    with self.exploration_rights_model_swap:
        exp_model = exp_models.ExplorationRightsModel(id=self.EXP_1_ID, owner_ids=[self.USER_1_ID, self.USER_2_ID], editor_ids=[self.USER_2_ID], voice_artist_ids=[], viewer_ids=[self.USER_4_ID], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.0)
        exp_model.save('cid', 'Created new exploration rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        exp_model.owner_ids = [self.USER_1_ID, self.USER_3_ID]
        exp_model.save('cid', 'Change owner', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_4_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    with self.topic_rights_model_swap:
        topic_model_1 = topic_models.TopicRightsModel(id=self.TOP_1_ID, manager_ids=[self.USER_1_ID, self.USER_2_ID])
        topic_model_1.commit('cid', 'Created new topic rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        topic_model_1.manager_ids = [self.USER_2_ID, self.USER_3_ID]
        topic_model_1.commit('cid', 'Change manager', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_3_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
        topic_model_2 = topic_models.TopicRightsModel(id=self.TOP_2_ID, manager_ids=[self.USER_1_ID])
        topic_model_2.commit('cid', 'Created new topic rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        topic_model_2.manager_ids = [self.USER_1_ID, self.USER_4_ID]
        topic_model_2.commit('cid', 'Change manager', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_3_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    output = self._run_one_off_job()
    self.assertIn(['SUCCESS-CollectionRightsSnapshotContentModel', 2], output)
    self.assertIn(['SUCCESS-ExplorationRightsSnapshotContentModel', 2], output)
    self.assertIn(['SUCCESS-TopicRightsSnapshotContentModel', 4], output)
    self.assertItemsEqual([self.USER_1_ID], collection_models.CollectionRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.COL_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_4_ID], collection_models.CollectionRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.COL_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID, self.USER_4_ID], exp_models.ExplorationRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.EXP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID, self.USER_3_ID, self.USER_4_ID], exp_models.ExplorationRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.EXP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.TOP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_2_ID, self.USER_3_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.TOP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.TOP_2_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_4_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.TOP_2_ID)).content_user_ids)
def test_add_content_user_ids_to_multiple_rights_snapshots(self):
    with self.collection_rights_model_swap:
        collection_model = collection_models.CollectionRightsModel(id=self.COL_1_ID, owner_ids=[self.USER_1_ID], editor_ids=[], voice_artist_ids=[], viewer_ids=[], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.0)
        collection_model.save('cid', 'Created new collection rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        collection_model.editor_ids = [self.USER_1_ID, self.USER_4_ID]
        collection_model.save('cid', 'Add editors', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_4_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    with self.exploration_rights_model_swap:
        exp_model = exp_models.ExplorationRightsModel(id=self.EXP_1_ID, owner_ids=[self.USER_1_ID, self.USER_2_ID], editor_ids=[self.USER_2_ID], voice_artist_ids=[], viewer_ids=[self.USER_4_ID], community_owned=False, status=constants.ACTIVITY_STATUS_PUBLIC, viewable_if_private=False, first_published_msec=0.0)
        exp_model.save('cid', 'Created new exploration rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        exp_model.owner_ids = [self.USER_1_ID, self.USER_3_ID]
        exp_model.save('cid', 'Change owner', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_4_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    with self.topic_rights_model_swap:
        topic_model_1 = topic_models.TopicRightsModel(id=self.TOP_1_ID, manager_ids=[self.USER_1_ID, self.USER_2_ID])
        topic_model_1.commit('cid', 'Created new topic rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        topic_model_1.manager_ids = [self.USER_2_ID, self.USER_3_ID]
        topic_model_1.commit('cid', 'Change manager', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_3_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
        topic_model_2 = topic_models.TopicRightsModel(id=self.TOP_2_ID, manager_ids=[self.USER_1_ID])
        topic_model_2.commit('cid', 'Created new topic rights', [{'cmd': rights_domain.CMD_CREATE_NEW}])
        topic_model_2.manager_ids = [self.USER_1_ID, self.USER_4_ID]
        topic_model_2.commit('cid', 'Change manager', [{'cmd': rights_domain.CMD_CHANGE_ROLE, 'assignee_id': self.USER_3_ID, 'old_role': rights_domain.ROLE_NONE, 'new_role': rights_domain.ROLE_OWNER}])
    output = self._run_one_off_job()
    self.assertIn(['SUCCESS-CollectionRightsSnapshotContentModel', 2], output)
    self.assertIn(['SUCCESS-ExplorationRightsSnapshotContentModel', 2], output)
    self.assertIn(['SUCCESS-TopicRightsSnapshotContentModel', 4], output)
    self.assertItemsEqual([self.USER_1_ID], collection_models.CollectionRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.COL_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_4_ID], collection_models.CollectionRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.COL_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID, self.USER_4_ID], exp_models.ExplorationRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.EXP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID, self.USER_3_ID, self.USER_4_ID], exp_models.ExplorationRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.EXP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_2_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.TOP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_2_ID, self.USER_3_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.TOP_1_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-1' % self.TOP_2_ID)).content_user_ids)
    self.assertItemsEqual([self.USER_1_ID, self.USER_4_ID], topic_models.TopicRightsSnapshotMetadataModel.get_by_id(('%s-2' % self.TOP_2_ID)).content_user_ids)