def test_thread_and_exploration_subscriptions_are_tracked_individually(self): self.assertEqual(self._get_thread_ids_subscribed_to(USER_ID), []) subscription_services.subscribe_to_thread(USER_ID, FEEDBACK_THREAD_ID) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_thread_ids_subscribed_to(USER_ID), [FEEDBACK_THREAD_ID]) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID])
def test_get_exploration_ids_subscribed_to(self): self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), []) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID_2) self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_ID_2])
def reduce(key, stringified_values): values = [ast.literal_eval(v) for v in stringified_values] for item in values: if item['type'] == 'feedback': subscription_services.subscribe_to_thread(key, item['id']) elif item['type'] == 'exploration': subscription_services.subscribe_to_exploration(key, item['id']) elif item['type'] == 'collection': subscription_services.subscribe_to_collection(key, item['id'])
def reduce(key, stringified_values): values = [ast.literal_eval(v) for v in stringified_values] for item in values: if item["type"] == "feedback": subscription_services.subscribe_to_thread(key, item["id"]) elif item["type"] == "exploration": subscription_services.subscribe_to_exploration(key, item["id"]) elif item["type"] == "collection": subscription_services.subscribe_to_collection(key, item["id"])
def test_get_exploration_ids_subscribed_to(self): USER_ID = "user_id" self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), []) EXP_ID = "exp_id" subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) EXP_2_ID = "exp_id_2" subscription_services.subscribe_to_exploration(USER_ID, EXP_2_ID) self.assertEqual(subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_2_ID])
def test_subscribed_exploration_cannot_be_added_to_playlist(self): # Subscribe to exploration. subscription_services.subscribe_to_exploration( self.user_id, self.EXP_ID_0) self.assertEqual( self._get_all_learner_playlist_exp_ids(self.user_id), []) # Now if we try to add the same exploration, it shouldn't be added. learner_progress_services.add_exp_to_learner_playlist( self.user_id, self.EXP_ID_0) self.assertEqual( self._get_all_learner_playlist_exp_ids(self.user_id), [])
def test_thread_and_exploration_subscriptions_are_tracked_individually( self): USER_ID = 'user_id' FEEDBACK_THREAD_ID = 'fthread_id' EXP_ID = 'exp_id' self.assertEqual(self._get_thread_ids_subscribed_to(USER_ID), []) subscription_services.subscribe_to_thread(USER_ID, FEEDBACK_THREAD_ID) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_thread_ids_subscribed_to(USER_ID), [FEEDBACK_THREAD_ID]) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID])
def test_get_exploration_ids_subscribed_to(self): self.assertEqual( subscription_services.get_exploration_ids_subscribed_to( USER_ID), []) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual( subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID_2) self.assertEqual( subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_ID_2])
def setUp(self): super(UserSubscriptionsModelValidatorTests, self).setUp() self.signup(self.OWNER_EMAIL, self.OWNER_USERNAME) self.signup(USER_EMAIL, USER_NAME) self.owner_id = self.get_user_id_from_email(self.OWNER_EMAIL) self.user_id = self.get_user_id_from_email(USER_EMAIL) self.owner = user_services.UserActionsInfo(self.owner_id) explorations = [exp_domain.Exploration.create_default_exploration( '%s' % i, title='title %d' % i, category='category%d' % i ) for i in xrange(3)] for exp in explorations: exp_services.save_new_exploration(self.owner_id, exp) rights_manager.publish_exploration(self.owner, exp.id) collections = [collection_domain.Collection.create_default_collection( '%s' % i, title='title %d' % i, category='category%d' % i ) for i in xrange(3, 6)] for collection in collections: collection_services.save_new_collection(self.owner_id, collection) rights_manager.publish_collection(self.owner, collection.id) thread_id = feedback_services.create_thread( 'exploration', 'exp_id', None, 'a subject', 'some text') subscription_services.subscribe_to_thread( self.user_id, thread_id) subscription_services.subscribe_to_creator(self.user_id, self.owner_id) for exp in explorations: subscription_services.subscribe_to_exploration( self.user_id, exp.id) for collection in collections: subscription_services.subscribe_to_collection( self.user_id, collection.id) self.process_and_flush_pending_tasks() prod_validation_jobs_one_off.MODEL_TO_VALIDATOR_MAPPING = { user_models.UserSubscriptionsModel: prod_validation_jobs_one_off.UserSubscriptionsModelValidator, }
def create_new_exploration_rights(exploration_id, committer_id): exploration_rights = ActivityRights(exploration_id, [committer_id], [], []) commit_cmds = [{"cmd": CMD_CREATE_NEW}] exp_models.ExplorationRightsModel( id=exploration_rights.id, owner_ids=exploration_rights.owner_ids, editor_ids=exploration_rights.editor_ids, viewer_ids=exploration_rights.viewer_ids, community_owned=exploration_rights.community_owned, status=exploration_rights.status, viewable_if_private=exploration_rights.viewable_if_private, first_published_msec=exploration_rights.first_published_msec, ).commit(committer_id, "Created new exploration", commit_cmds) subscription_services.subscribe_to_exploration(committer_id, exploration_id)
def create_new_exploration_rights(exploration_id, committer_id): exploration_rights = ActivityRights(exploration_id, [committer_id], [], []) commit_cmds = [{'cmd': CMD_CREATE_NEW}] exp_models.ExplorationRightsModel( id=exploration_rights.id, owner_ids=exploration_rights.owner_ids, editor_ids=exploration_rights.editor_ids, viewer_ids=exploration_rights.viewer_ids, community_owned=exploration_rights.community_owned, status=exploration_rights.status, viewable_if_private=exploration_rights.viewable_if_private, ).commit(committer_id, 'Created new exploration', commit_cmds) subscription_services.subscribe_to_exploration(committer_id, exploration_id)
def assign_role_for_exploration(committer_id, exploration_id, assignee_id, new_role): """Assign `assignee_id` to the given role and subscribes the assignee to future exploration updates. The caller should ensure that assignee_id corresponds to a valid user in the system. Args: - committer_id: str. The user_id of the user who is performing the action. - exploration_id: str. The exploration id. - assignee_id: str. The user_id of the user whose role is being changed. - new_role: str. The name of the new role: either 'owner', 'editor' or 'viewer'. """ _assign_role(committer_id, assignee_id, new_role, exploration_id, feconf.ACTIVITY_TYPE_EXPLORATION) if new_role in [ROLE_OWNER, ROLE_EDITOR]: subscription_services.subscribe_to_exploration(assignee_id, exploration_id)
def test_get_exploration_ids_subscribed_to(self): USER_ID = 'user_id' self.assertEqual( subscription_services.get_exploration_ids_subscribed_to(USER_ID), []) EXP_ID = 'exp_id' subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual( subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) EXP_2_ID = 'exp_id_2' subscription_services.subscribe_to_exploration(USER_ID, EXP_2_ID) self.assertEqual( subscription_services.get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_2_ID])
def assign_role_for_exploration(committer_id, exploration_id, assignee_id, new_role): """Assign `assignee_id` to the given role and subscribes the assignee to future exploration updates. The caller should ensure that assignee_id corresponds to a valid user in the system. Args: - committer_id: str. The user_id of the user who is performing the action. - exploration_id: str. The exploration id. - assignee_id: str. The user_id of the user whose role is being changed. - new_role: str. The name of the new role: either 'owner', 'editor' or 'viewer'. """ _assign_role(committer_id, assignee_id, new_role, exploration_id, ACTIVITY_TYPE_EXPLORATION) if new_role in [ROLE_OWNER, ROLE_EDITOR]: subscription_services.subscribe_to_exploration(assignee_id, exploration_id)
def create_new_exploration_rights(exploration_id, committer_id): """Creates a new exploration rights object and saves it to the datastore. Subscribes the committer to the new exploration. Args: exploration_id: str. ID of the exploration. committer_id: str. ID of the committer. """ exploration_rights = ActivityRights(exploration_id, [committer_id], [], []) commit_cmds = [{'cmd': CMD_CREATE_NEW}] exp_models.ExplorationRightsModel( id=exploration_rights.id, owner_ids=exploration_rights.owner_ids, editor_ids=exploration_rights.editor_ids, viewer_ids=exploration_rights.viewer_ids, community_owned=exploration_rights.community_owned, status=exploration_rights.status, viewable_if_private=exploration_rights.viewable_if_private, first_published_msec=exploration_rights.first_published_msec, ).commit(committer_id, 'Created new exploration', commit_cmds) subscription_services.subscribe_to_exploration(committer_id, exploration_id)
def test_subscribe_to_exploration(self): self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), []) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) # Repeated subscriptions to the same exploration have no effect. subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) subscription_services.subscribe_to_exploration(USER_ID, EXP_ID_2) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_ID_2])
def test_subscribe_to_exploration(self): USER_ID = "user_id" self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), []) EXP_ID = "exp_id" subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) # Repeated subscriptions to the same exploration have no effect. subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) EXP_2_ID = "exp_id_2" subscription_services.subscribe_to_exploration(USER_ID, EXP_2_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_2_ID])
def test_subscribe_to_exploration(self): USER_ID = 'user_id' self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), []) EXP_ID = 'exp_id' subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) # Repeated subscriptions to the same exploration have no effect. subscription_services.subscribe_to_exploration(USER_ID, EXP_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID]) EXP_2_ID = 'exp_id_2' subscription_services.subscribe_to_exploration(USER_ID, EXP_2_ID) self.assertEqual(self._get_exploration_ids_subscribed_to(USER_ID), [EXP_ID, EXP_2_ID])