def test_short_userbio_returns_empty_list(self):
     """Tests the case where the userbio is less than 500 characters."""
     self.signup(self.USER_A_EMAIL, self.USER_A_USERNAME)
     user_id_a = self.get_user_id_from_email(self.USER_A_EMAIL)
     user_services.update_user_bio(user_id_a, self.USER_A_BIO)
     result = self._run_one_off_job()
     self.assertEqual(result, [])
Exemple #2
0
    def put(self):
        """Handles POST requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')

        if update_type == 'user_bio':
            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'subject_interests':
            user_services.update_subject_interests(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'preferred_site_language_code':
            user_services.update_preferred_site_language_code(
                self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        elif update_type == 'email_preferences':
            user_services.update_email_preferences(
                self.user_id, data['can_receive_email_updates'],
                data['can_receive_editor_role_email'],
                data['can_receive_feedback_message_email'])
        else:
            raise self.InvalidInputException(
                'Invalid update type: %s' % update_type)

        self.render_json({})
Exemple #3
0
    def put(self):
        """Handles POST requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')

        if update_type == 'user_bio':
            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'subject_interests':
            user_services.update_subject_interests(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'preferred_site_language_code':
            user_services.update_preferred_site_language_code(
                self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        elif update_type == 'email_preferences':
            user_services.update_email_preferences(
                self.user_id, data['can_receive_email_updates'],
                data['can_receive_editor_role_email'],
                data['can_receive_feedback_message_email'])
        else:
            raise self.InvalidInputException('Invalid update type: %s' %
                                             update_type)

        self.render_json({})
 def test_long_userbio_length(self):
     """Tests the case where the userbio is more than 500 characters."""
     self.signup(self.USER_B_EMAIL, self.USER_B_USERNAME)
     user_id_b = self.get_user_id_from_email(self.USER_B_EMAIL)
     user_services.update_user_bio(user_id_b, self.USER_B_BIO)
     result = self._run_one_off_job()
     expected_result = [[800, ['b']]]
     self.assertEqual(result, expected_result)
 def test_diff_userbio_length(self):
     """Tests the case where two users have different userbio lengths."""
     self.signup(self.USER_D_EMAIL, self.USER_D_USERNAME)
     user_id_d = self.get_user_id_from_email(self.USER_D_EMAIL)
     user_services.update_user_bio(user_id_d, self.USER_D_BIO)
     self.signup(self.USER_C_EMAIL, self.USER_C_USERNAME)
     user_id_c = self.get_user_id_from_email(self.USER_C_EMAIL)
     user_services.update_user_bio(user_id_c, self.USER_C_BIO)
     result = self._run_one_off_job()
     expected_result = [[800, ['c']], [2400, ['d']]]
     self.assertEqual(result, expected_result)
 def test_same_userbio_length(self):
     """Tests the case where two users have same userbio length."""
     self.signup(self.USER_B_EMAIL, self.USER_B_USERNAME)
     user_id_b = self.get_user_id_from_email(self.USER_B_EMAIL)
     user_services.update_user_bio(user_id_b, self.USER_B_BIO)
     self.signup(self.USER_C_EMAIL, self.USER_C_USERNAME)
     user_id_c = self.get_user_id_from_email(self.USER_C_EMAIL)
     user_services.update_user_bio(user_id_c, self.USER_C_BIO)
     result = self._run_one_off_job()
     result[0][1].sort()
     expected_result = [[800, ['b', 'c']]]
     self.assertEqual(result, expected_result)
Exemple #7
0
    def put(self):
        """Handles POST requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')

        if update_type == 'user_bio':
            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        else:
            raise self.InvalidInputException('Invalid update type: %s' %
                                             update_type)
Exemple #8
0
    def put(self):
        """Handles POST requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')

        if update_type == 'user_bio':
            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        else:
            raise self.InvalidInputException(
                'Invalid update type: %s' % update_type)
Exemple #9
0
    def test_created_on_gets_updated_correctly(self):
        # created_on should not be updated upon updating other attributes of
        # the user settings model.
        user_settings = user_services.create_new_user('auth_id',
                                                      '*****@*****.**')

        user_settings_model = user_models.UserSettingsModel.get_by_id(
            user_settings.user_id)
        time_of_creation = user_settings_model.created_on

        user_services.update_user_bio(user_settings.user_id, 'New bio.')

        user_settings_model = user_models.UserSettingsModel.get_by_id(
            user_settings.user_id)
        self.assertEqual(user_settings_model.created_on, time_of_creation)
Exemple #10
0
    def put(self):
        """Handles POST requests."""
        update_type = self.payload.get("update_type")
        data = self.payload.get("data")

        if update_type == "user_bio":
            user_services.update_user_bio(self.user_id, data)
        elif update_type == "preferred_language_codes":
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == "profile_picture_data_url":
            user_services.update_profile_picture_data_url(self.user_id, data)
        elif update_type == "can_receive_email_updates":
            user_services.update_email_preferences(self.user_id, data)
        else:
            raise self.InvalidInputException("Invalid update type: %s" % update_type)
Exemple #11
0
    def put(self):
        """Handles PUT requests."""
        update_type = self.payload.get('update_type')
        data = self.payload.get('data')
        bulk_email_signup_message_should_be_shown = False
        if update_type == 'user_bio':
            if len(data) > feconf.MAX_BIO_LENGTH_IN_CHARS:
                raise self.InvalidInputException(
                    'User bio exceeds maximum character limit: %s'
                    % feconf.MAX_BIO_LENGTH_IN_CHARS)

            user_services.update_user_bio(self.user_id, data)
        elif update_type == 'subject_interests':
            user_services.update_subject_interests(self.user_id, data)
        elif update_type == 'preferred_language_codes':
            user_services.update_preferred_language_codes(self.user_id, data)
        elif update_type == 'preferred_site_language_code':
            user_services.update_preferred_site_language_code(
                self.user_id, data)
        elif update_type == 'preferred_audio_language_code':
            user_services.update_preferred_audio_language_code(
                self.user_id, data)
        elif update_type == 'preferred_translation_language_code':
            user_services.update_preferred_translation_language_code(
                self.user_id, data)
        elif update_type == 'profile_picture_data_url':
            user_services.update_profile_picture_data_url(self.user_id, data)
        elif update_type == 'default_dashboard':
            user_services.update_user_default_dashboard(self.user_id, data)
        elif update_type == 'email_preferences':
            bulk_email_signup_message_should_be_shown = (
                user_services.update_email_preferences(
                    self.user_id, data['can_receive_email_updates'],
                    data['can_receive_editor_role_email'],
                    data['can_receive_feedback_message_email'],
                    data['can_receive_subscription_email']))
        else:
            raise self.InvalidInputException(
                'Invalid update type: %s' % update_type)

        self.render_json({
            'bulk_email_signup_message_should_be_shown': (
                bulk_email_signup_message_should_be_shown)
        })