From 138b3b35e039ae5a6a059335ec65182977901837 Mon Sep 17 00:00:00 2001 From: asadazam93 Date: Fri, 2 Aug 2019 16:11:31 +0500 Subject: [PATCH] social link validation --- .../core/djangoapps/user_api/accounts/serializers.py | 11 +++++++++++ .../djangoapps/user_api/accounts/tests/test_api.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/user_api/accounts/serializers.py b/openedx/core/djangoapps/user_api/accounts/serializers.py index c4072f1324..20178b0cb5 100644 --- a/openedx/core/djangoapps/user_api/accounts/serializers.py +++ b/openedx/core/djangoapps/user_api/accounts/serializers.py @@ -67,6 +67,17 @@ class SocialLinkSerializer(serializers.ModelSerializer): model = SocialLink fields = ("platform", "social_link") + def validate_platform(self, platform): + """ + Validate that the platform value is one of (facebook, twitter or linkedin) + """ + valid_platforms = ["facebook", "twitter", "linkedin"] + if platform not in valid_platforms: + raise serializers.ValidationError( + u"The social platform must be facebook, twitter or linkedin" + ) + return platform + class UserReadOnlySerializer(serializers.Serializer): """ diff --git a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py index f52f5a1113..9f6a1e9dc9 100644 --- a/openedx/core/djangoapps/user_api/accounts/tests/test_api.py +++ b/openedx/core/djangoapps/user_api/accounts/tests/test_api.py @@ -217,7 +217,7 @@ class TestAccountApi(UserSettingsEventTestMixin, EmailTemplateTagMixin, Retireme social_links = [ dict(platform="unsupported", social_link="https://www.unsupported.com/{}".format(self.user.username)) ] - with self.assertRaises(AccountUpdateError): + with self.assertRaises(AccountValidationError): update_account_settings(self.user, {"social_links": social_links}) def test_update_success_for_enterprise(self):