Exemplo n.º 1
0
    def test_unsubscribe_handler(self):
        """Test handler for unsubscriptions."""

        payload = {
            'creator_username': self.EDITOR_USERNAME
        }

        # Add one subscription to editor.
        self.login(self.USER_EMAIL)
        response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(
            feconf.SUBSCRIBE_URL_PREFIX, payload,
            csrf_token=csrf_token)
        self.logout()

        # Add another subscription.
        self.login(self.USER2_EMAIL)
        response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(
            feconf.SUBSCRIBE_URL_PREFIX, payload,
            csrf_token=csrf_token)

        # Test that on unsubscription, the learner ID is removed from the
        # list of subscriber IDs of the creator and the creator ID is
        # removed from the list of subscriptions of the learner.
        self.post_json(
            feconf.UNSUBSCRIBE_URL_PREFIX, payload,
            csrf_token=csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [])

        # Unsubscribing the same user has no effect.
        self.post_json(
            feconf.UNSUBSCRIBE_URL_PREFIX, payload,
            csrf_token=csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [])

        self.logout()

        # Unsubscribing another user.
        self.login(self.USER_EMAIL)
        response = self.testapp.get(feconf.CREATOR_DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(
            feconf.UNSUBSCRIBE_URL_PREFIX, payload,
            csrf_token=csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id), [])
    def test_get_all_creators_subscribed_to(self):
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(USER_ID), [])

        subscription_services.subscribe_to_creator(USER_ID, self.owner_id)
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(USER_ID),
            [self.owner_id])

        subscription_services.subscribe_to_creator(USER_ID, self.owner_2_id)
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(USER_ID),
            [self.owner_id, self.owner_2_id])
Exemplo n.º 3
0
    def test_subscribe_handler(self):
        """Test handler for new subscriptions to creators."""

        self.login(self.USER_EMAIL)
        response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)

        payload = {'creator_username': self.EDITOR_USERNAME}

        # Test that the subscriber ID is added to the list of subscribers
        # of the creator and the creator ID is added to the list of
        # subscriptions of the user.
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX,
                       payload,
                       csrf_token=csrf_token)
        self.assertEqual(
            subscription_services.get_all_subscribers_of_creator(
                self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(self.user_id),
            [self.editor_id])

        # Subscribing again, has no effect.
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX,
                       payload,
                       csrf_token=csrf_token)
        self.assertEqual(
            subscription_services.get_all_subscribers_of_creator(
                self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(self.user_id),
            [self.editor_id])

        self.logout()

        # Test another user subscription.
        self.login(self.USER2_EMAIL)
        response = self.get_html_response(feconf.CREATOR_DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)

        self.post_json(feconf.SUBSCRIBE_URL_PREFIX,
                       payload,
                       csrf_token=csrf_token)
        self.assertEqual(
            subscription_services.get_all_subscribers_of_creator(
                self.editor_id), [self.user_id, self.user_id_2])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [self.editor_id])
        self.logout()
Exemplo n.º 4
0
    def test_get_all_creators_subscribed_to(self):
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                USER_ID), [])

        subscription_services.subscribe_to_creator(USER_ID, self.owner_id)
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                USER_ID), [self.owner_id])

        subscription_services.subscribe_to_creator(USER_ID, self.owner_2_id)
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                USER_ID), [self.owner_id, self.owner_2_id])
Exemplo n.º 5
0
    def test_unsubscribe_handler(self):
        """Test handler for unsubscriptions."""

        payload = {
            'creator_username': self.EDITOR_USERNAME
        }

        # Add one subscription to editor.
        self.login(self.USER_EMAIL)
        response = self.testapp.get(feconf.DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.logout()

        # Add another subscription.
        self.login(self.USER2_EMAIL)
        response = self.testapp.get(feconf.DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX, payload, csrf_token)

        # Test that on unsubscription, the learner ID is removed from the
        # list of subscriber IDs of the creator and the creator ID is
        # removed from the list of subscriptions of the learner.
        self.post_json(feconf.UNSUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [])

        # Unsubscribing the same user has no effect.
        self.post_json(feconf.UNSUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [])

        self.logout()

        # Unsubscribing another user.
        self.login(self.USER_EMAIL)
        response = self.testapp.get(feconf.DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)
        self.post_json(feconf.UNSUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id), [])
Exemplo n.º 6
0
    def test_subscribe_handler(self):
        """Test handler for new subscriptions to creators"""

        self.login(self.USER_EMAIL)
        response = self.testapp.get(feconf.DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)

        payload = {
            'creator_username': self.EDITOR_USERNAME
        }

        # Test that the subscriber ID is added to the list of subscribers
        # of the creator and the creator ID is added to the list of
        # subscriptions of the user.
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id), [self.editor_id])

        # Subscribing again, has no effect.
        self.post_json(feconf.SUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id), [self.editor_id])

        self.logout()

        # Test another user subscription.
        self.login(self.USER2_EMAIL)
        response = self.testapp.get(feconf.DASHBOARD_URL)
        csrf_token = self.get_csrf_token_from_response(response)

        self.post_json(feconf.SUBSCRIBE_URL_PREFIX, payload, csrf_token)
        self.assertEqual(subscription_services.get_all_subscribers_of_creator(
            self.editor_id), [self.user_id, self.user_id_2])
        self.assertEqual(
            subscription_services.get_all_creators_subscribed_to(
                self.user_id_2), [self.editor_id])
        self.logout()
Exemplo n.º 7
0
    def get(self):
        """Handles GET requests."""
        user_settings = user_services.get_user_settings(self.user_id)
        user_email_preferences = user_services.get_email_preferences(
            self.user_id)

        creators_subscribed_to = subscription_services.get_all_creators_subscribed_to(  # pylint: disable=line-too-long
            self.user_id)
        creators_settings = user_services.get_users_settings(
            creators_subscribed_to)
        subscription_list = []

        for index, creator_settings in enumerate(creators_settings):
            subscription_summary = {
                'creator_picture_data_url':
                (creator_settings.profile_picture_data_url),
                'creator_username':
                creator_settings.username,
                'creator_impact': (user_services.get_user_impact_score(
                    creators_subscribed_to[index]))
            }

            subscription_list.append(subscription_summary)

        self.values.update({
            'preferred_language_codes':
            user_settings.preferred_language_codes,
            'preferred_site_language_code':
            (user_settings.preferred_site_language_code),
            'preferred_audio_language_code':
            (user_settings.preferred_audio_language_code),
            'profile_picture_data_url':
            user_settings.profile_picture_data_url,
            'default_dashboard':
            user_settings.default_dashboard,
            'user_bio':
            user_settings.user_bio,
            'subject_interests':
            user_settings.subject_interests,
            'can_receive_email_updates':
            (user_email_preferences.can_receive_email_updates),
            'can_receive_editor_role_email':
            (user_email_preferences.can_receive_editor_role_email),
            'can_receive_feedback_message_email':
            (user_email_preferences.can_receive_feedback_message_email),
            'can_receive_subscription_email':
            (user_email_preferences.can_receive_subscription_email),
            'subscription_list':
            subscription_list
        })
        self.render_json(self.values)
Exemplo n.º 8
0
    def get(self):
        """Handles GET requests."""
        (learner_progress, number_of_nonexistent_explorations) = (
            learner_progress_services.get_exploration_progress(self.user_id))

        completed_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.completed_exp_summaries))

        incomplete_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.incomplete_exp_summaries))

        exploration_playlist_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.exploration_playlist_summaries))

        creators_subscribed_to = (
            subscription_services.get_all_creators_subscribed_to(self.user_id))
        creators_settings = user_services.get_users_settings(
            creators_subscribed_to)
        subscription_list = []

        for index, creator_settings in enumerate(creators_settings):
            subscription_summary = {
                'creator_picture_data_url':
                (creator_settings.profile_picture_data_url),
                'creator_username':
                creator_settings.username,
                'creator_impact': (user_services.get_user_impact_score(
                    creators_subscribed_to[index]))
            }

            subscription_list.append(subscription_summary)

        self.values.update({
            'completed_explorations_list':
            completed_exp_summary_dicts,
            'incomplete_explorations_list':
            incomplete_exp_summary_dicts,
            'exploration_playlist':
            exploration_playlist_summary_dicts,
            'number_of_nonexistent_explorations':
            (number_of_nonexistent_explorations),
            'subscription_list':
            subscription_list
        })
        self.render_json(self.values)
Exemplo n.º 9
0
    def get(self):
        """Handles GET requests."""
        user_settings = user_services.get_user_settings(self.user_id)
        user_email_preferences = user_services.get_email_preferences(
            self.user_id)

        creators_subscribed_to = subscription_services.get_all_creators_subscribed_to( # pylint: disable=line-too-long
            self.user_id)
        creators_settings = user_services.get_users_settings(
            creators_subscribed_to)
        subscription_list = []

        for index, creator_settings in enumerate(creators_settings):
            subscription_summary = {
                'creator_picture_data_url': (
                    creator_settings.profile_picture_data_url),
                'creator_username': creator_settings.username,
                'creator_impact': (
                    user_services.get_user_impact_score(
                        creators_subscribed_to[index]))
            }

            subscription_list.append(subscription_summary)

        self.values.update({
            'preferred_language_codes': user_settings.preferred_language_codes,
            'preferred_site_language_code': (
                user_settings.preferred_site_language_code),
            'profile_picture_data_url': user_settings.profile_picture_data_url,
            'user_bio': user_settings.user_bio,
            'subject_interests': user_settings.subject_interests,
            'can_receive_email_updates': (
                user_email_preferences.can_receive_email_updates),
            'can_receive_editor_role_email': (
                user_email_preferences.can_receive_editor_role_email),
            'can_receive_feedback_message_email': (
                user_email_preferences.can_receive_feedback_message_email),
            'can_receive_subscription_email': (
                user_email_preferences.can_receive_subscription_email),
            'subscription_list': subscription_list
        })
        self.render_json(self.values)
Exemplo n.º 10
0
    def get(self):
        """Handles GET requests."""
        (
            learner_progress, number_of_nonexistent_activities,
            completed_to_incomplete_collections) = (
                learner_progress_services.get_activity_progress(self.user_id))

        completed_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.completed_exp_summaries))

        incomplete_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.incomplete_exp_summaries))

        completed_collection_summary_dicts = (
            learner_progress_services.get_collection_summary_dicts(
                learner_progress.completed_collection_summaries))
        incomplete_collection_summary_dicts = (
            learner_progress_services.get_collection_summary_dicts(
                learner_progress.incomplete_collection_summaries))

        exploration_playlist_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                learner_progress.exploration_playlist_summaries))
        collection_playlist_summary_dicts = (
            learner_progress_services.get_collection_summary_dicts(
                learner_progress.collection_playlist_summaries))

        full_thread_ids = subscription_services.get_all_threads_subscribed_to(
            self.user_id)
        if len(full_thread_ids) > 0:
            thread_summaries, number_of_unread_threads = (
                feedback_services.get_exp_thread_summaries(
                    self.user_id, full_thread_ids))
        else:
            thread_summaries, number_of_unread_threads = [], 0

        creators_subscribed_to = (
            subscription_services.get_all_creators_subscribed_to(self.user_id))
        creators_settings = user_services.get_users_settings(
            creators_subscribed_to)
        subscription_list = []

        for index, creator_settings in enumerate(creators_settings):
            subscription_summary = {
                'creator_picture_data_url': (
                    creator_settings.profile_picture_data_url),
                'creator_username': creator_settings.username,
                'creator_impact': (
                    user_services.get_user_impact_score(
                        creators_subscribed_to[index]))
            }

            subscription_list.append(subscription_summary)

        self.values.update({
            'completed_explorations_list': completed_exp_summary_dicts,
            'completed_collections_list': completed_collection_summary_dicts,
            'incomplete_explorations_list': incomplete_exp_summary_dicts,
            'incomplete_collections_list': incomplete_collection_summary_dicts,
            'exploration_playlist': exploration_playlist_summary_dicts,
            'collection_playlist': collection_playlist_summary_dicts,
            'number_of_nonexistent_activities': (
                number_of_nonexistent_activities),
            'completed_to_incomplete_collections': (
                completed_to_incomplete_collections),
            'thread_summaries': [s.to_dict() for s in thread_summaries],
            'number_of_unread_threads': number_of_unread_threads,
            'subscription_list': subscription_list
        })
        self.render_json(self.values)
Exemplo n.º 11
0
    def get(self):
        """Handles GET requests."""
        if self.user_id is None:
            raise self.PageNotFoundException

        incomplete_exp_summaries, num_deleted_incomplete_exps = (
            learner_progress_services.get_incomplete_exp_summaries(
                self.user_id))

        completed_exp_summaries, num_deleted_completed_exps = (
            learner_progress_services.get_completed_exp_summaries(
                self.user_id))

        (completed_collection_summaries, num_deleted_completed_collections,
         completed_to_incomplete_collections) = (
             learner_progress_services.get_completed_collection_summaries(
                 self.user_id))

        incomplete_collection_summaries, num_deleted_incomplete_collections = (
            learner_progress_services.get_incomplete_collection_summaries(
                self.user_id))

        completed_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                completed_exp_summaries))

        incomplete_exp_summary_dicts = (
            summary_services.get_displayable_exp_summary_dicts(
                incomplete_exp_summaries))

        completed_collection_summary_dicts = (
            learner_progress_services.get_collection_summary_dicts(
                completed_collection_summaries))
        incomplete_collection_summary_dicts = (
            learner_progress_services.get_collection_summary_dicts(
                incomplete_collection_summaries))

        creators_subscribed_to = (
            subscription_services.get_all_creators_subscribed_to(self.user_id))
        creators_settings = user_services.get_users_settings(
            creators_subscribed_to)
        subscription_list = []

        for index, creator_settings in enumerate(creators_settings):
            subscription_summary = {
                'creator_picture_data_url':
                (creator_settings.profile_picture_data_url),
                'creator_username':
                creator_settings.username,
                'creator_impact': (user_services.get_user_impact_score(
                    creators_subscribed_to[index]))
            }

            subscription_list.append(subscription_summary)

        self.values.update({
            'completed_explorations_list':
            completed_exp_summary_dicts,
            'completed_collections_list':
            completed_collection_summary_dicts,
            'incomplete_explorations_list':
            incomplete_exp_summary_dicts,
            'incomplete_collections_list':
            incomplete_collection_summary_dicts,
            'number_of_deleted_activities': {
                'incomplete_explorations': num_deleted_incomplete_exps,
                'incomplete_collections': num_deleted_incomplete_collections,
                'completed_explorations': num_deleted_completed_exps,
                'completed_collections': num_deleted_completed_collections
            },
            'completed_to_incomplete_collections':
            (completed_to_incomplete_collections),
            'subscription_list':
            subscription_list
        })
        self.render_json(self.values)