Commit 00b3051b by J. Cliff Dyer

Make sure proper logic is used for getting account privacy.

parent 222bdd98
......@@ -66,7 +66,7 @@ class MembershipSerializerTestCase(SerializerTestCase):
'image_url_small': 'http://testserver/static/default_30.png',
'has_image': False
},
'account_privacy': None
'account_privacy': 'private'
})
self.assertNotIn('membership', data['team'])
......
......@@ -129,7 +129,7 @@ class TestDashboard(SharedModuleStoreTestCase):
team.add_user(self.user)
# Check the query count on the dashboard again
with self.assertNumQueries(20):
with self.assertNumQueries(19):
self.client.get(self.teams_url)
def test_bad_course_id(self):
......
......@@ -91,7 +91,7 @@ class UserReadOnlySerializer(serializers.Serializer):
"level_of_education": AccountLegacyProfileSerializer.convert_empty_to_None(profile.level_of_education),
"mailing_address": profile.mailing_address,
"requires_parental_consent": profile.requires_parental_consent(),
"account_privacy": UserPreference.get_value(user, 'account_privacy'),
"account_privacy": self._get_profile_visibility(profile, user),
}
return self._filter_fields(
......@@ -185,19 +185,19 @@ class AccountLegacyProfileSerializer(serializers.HyperlinkedModelSerializer, Rea
raise serializers.ValidationError("The language_proficiencies field must consist of unique languages")
return value
def transform_gender(self, user_profile, value):
def transform_gender(self, user_profile, value): # pylint: disable=unused-argument
""" Converts empty string to None, to indicate not set. Replaced by to_representation in version 3. """
return AccountLegacyProfileSerializer.convert_empty_to_None(value)
def transform_country(self, user_profile, value):
def transform_country(self, user_profile, value): # pylint: disable=unused-argument
""" Converts empty string to None, to indicate not set. Replaced by to_representation in version 3. """
return AccountLegacyProfileSerializer.convert_empty_to_None(value)
def transform_level_of_education(self, user_profile, value):
def transform_level_of_education(self, user_profile, value): # pylint: disable=unused-argument
""" Converts empty string to None, to indicate not set. Replaced by to_representation in version 3. """
return AccountLegacyProfileSerializer.convert_empty_to_None(value)
def transform_bio(self, user_profile, value):
def transform_bio(self, user_profile, value): # pylint: disable=unused-argument
""" Converts empty string to None, to indicate not set. Replaced by to_representation in version 3. """
return AccountLegacyProfileSerializer.convert_empty_to_None(value)
......
......@@ -25,7 +25,7 @@ from ...errors import (
from ..api import (
get_account_settings, update_account_settings, create_account, activate_account, request_password_change
)
from .. import USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH, PASSWORD_MAX_LENGTH
from .. import USERNAME_MAX_LENGTH, EMAIL_MAX_LENGTH, PASSWORD_MAX_LENGTH, PRIVATE_VISIBILITY
def mock_render_to_string(template_name, context):
......@@ -278,7 +278,7 @@ class AccountSettingsOnCreationTest(TestCase):
},
'requires_parental_consent': True,
'language_proficiencies': [],
'account_privacy': None
'account_privacy': PRIVATE_VISIBILITY,
})
......@@ -404,7 +404,7 @@ class AccountCreationActivationAndPasswordChangeTest(TestCase):
# Verify that the body of the message contains something that looks
# like an activation link
email_body = mail.outbox[0].body
result = re.search('(?P<url>https?://[^\s]+)', email_body)
result = re.search(r'(?P<url>https?://[^\s]+)', email_body)
self.assertIsNot(result, None)
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS')
......
......@@ -241,7 +241,7 @@ class TestAccountAPI(UserAPITestCase):
self.create_mock_profile(self.user)
with self.assertNumQueries(9):
response = self.send_get(self.different_client)
self._verify_full_shareable_account_response(response)
self._verify_full_shareable_account_response(response, account_privacy=ALL_USERS_VISIBILITY)
# Note: using getattr so that the patching works even if there is no configuration.
# This is needed when testing CMS as the patching is still executed even though the
......@@ -256,7 +256,7 @@ class TestAccountAPI(UserAPITestCase):
self.create_mock_profile(self.user)
with self.assertNumQueries(9):
response = self.send_get(self.different_client)
self._verify_private_account_response(response)
self._verify_private_account_response(response, account_privacy=PRIVATE_VISIBILITY)
@ddt.data(
("client", "user", PRIVATE_VISIBILITY),
......@@ -305,7 +305,7 @@ class TestAccountAPI(UserAPITestCase):
"""
Internal helper to perform the actual assertions
"""
with self.assertNumQueries(8):
with self.assertNumQueries(7):
response = self.send_get(self.client)
data = response.data
self.assertEqual(16, len(data))
......@@ -322,7 +322,7 @@ class TestAccountAPI(UserAPITestCase):
self._verify_profile_image_data(data, False)
self.assertTrue(data["requires_parental_consent"])
self.assertEqual([], data["language_proficiencies"])
self.assertEqual(None, data["account_privacy"])
self.assertEqual(PRIVATE_VISIBILITY, data["account_privacy"])
self.client.login(username=self.user.username, password=self.test_password)
verify_get_own_information()
......@@ -344,7 +344,7 @@ class TestAccountAPI(UserAPITestCase):
legacy_profile.save()
self.client.login(username=self.user.username, password=self.test_password)
with self.assertNumQueries(8):
with self.assertNumQueries(7):
response = self.send_get(self.client)
for empty_field in ("level_of_education", "gender", "country", "bio"):
self.assertIsNone(response.data[empty_field])
......@@ -403,6 +403,14 @@ class TestAccountAPI(UserAPITestCase):
Test the behavior of patch, when using the correct content_type.
"""
client = self.login_client("client", "user")
if field == 'account_privacy':
# Ensure the user has birth year set, and is over 13, so
# account_privacy behaves normally
legacy_profile = UserProfile.objects.get(id=self.user.id)
legacy_profile.year_of_birth = 2000
legacy_profile.save()
response = self.send_patch(client, {field: value})
self.assertEqual(value, response.data[field])
......@@ -687,16 +695,16 @@ class TestAccountAPI(UserAPITestCase):
self.assertIsNotNone(data["date_joined"])
self._verify_profile_image_data(data, False)
self.assertTrue(data["requires_parental_consent"])
self.assertEqual(ALL_USERS_VISIBILITY, data["account_privacy"])
self.assertEqual(PRIVATE_VISIBILITY, data["account_privacy"])
else:
self._verify_private_account_response(
response, requires_parental_consent=True, account_privacy=ALL_USERS_VISIBILITY
response, requires_parental_consent=True, account_privacy=PRIVATE_VISIBILITY
)
# Verify that the shared view is still private
response = self.send_get(client, query_parameters='view=shared')
self._verify_private_account_response(
response, requires_parental_consent=True, account_privacy=ALL_USERS_VISIBILITY
response, requires_parental_consent=True, account_privacy=PRIVATE_VISIBILITY
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment