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 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 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) })
def test_invalid_subject_interests_are_not_accepted(self): with self.assertRaisesRegexp(utils.ValidationError, 'to be a list'): user_services.update_subject_interests(self.user_id, 'not a list') with self.assertRaisesRegexp(utils.ValidationError, 'to be a string'): user_services.update_subject_interests(self.user_id, [1, 2, 3]) with self.assertRaisesRegexp(utils.ValidationError, 'to be non-empty'): user_services.update_subject_interests(self.user_id, ['', 'ab']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests(self.user_id, ['!']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests(self.user_id, ['has-hyphens']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests(self.user_id, ['HasCapitalLetters']) with self.assertRaisesRegexp(utils.ValidationError, 'to be distinct'): user_services.update_subject_interests(self.user_id, ['a', 'a']) # The following cases are all valid. user_services.update_subject_interests(self.user_id, []) user_services.update_subject_interests(self.user_id, ['singleword', 'has spaces'])
def test_invalid_subject_interests_are_not_accepted(self): with self.assertRaisesRegexp(utils.ValidationError, 'to be a list'): user_services.update_subject_interests(self.user_id, 'not a list') with self.assertRaisesRegexp(utils.ValidationError, 'to be a string'): user_services.update_subject_interests(self.user_id, [1, 2, 3]) with self.assertRaisesRegexp(utils.ValidationError, 'to be non-empty'): user_services.update_subject_interests(self.user_id, ['', 'ab']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests(self.user_id, ['!']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests( self.user_id, ['has-hyphens']) with self.assertRaisesRegexp( utils.ValidationError, 'to consist only of lowercase alphabetic characters and spaces' ): user_services.update_subject_interests( self.user_id, ['HasCapitalLetters']) with self.assertRaisesRegexp(utils.ValidationError, 'to be distinct'): user_services.update_subject_interests(self.user_id, ['a', 'a']) # The following cases are all valid. user_services.update_subject_interests(self.user_id, []) user_services.update_subject_interests( self.user_id, ['singleword', 'has spaces'])