From a99498a16b98000075acf148486298cbdc73c3be Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 5 May 2015 17:02:16 +0200 Subject: [PATCH] bugfix(mp): update boolean field on member --- zds/member/api/serializers.py | 15 +++++++++------ zds/member/api/tests.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/zds/member/api/serializers.py b/zds/member/api/serializers.py index 3fc4e3c6cf..874b053519 100644 --- a/zds/member/api/serializers.py +++ b/zds/member/api/serializers.py @@ -104,12 +104,15 @@ def update(self, instance, validated_data): instance.avatar_url = validated_data.get('avatar_url', instance.avatar_url) or instance.avatar_url instance.biography = validated_data.get('biography', instance.biography) or instance.biography instance.sign = validated_data.get('sign', instance.sign) or instance.sign - instance.show_email = validated_data.get('show_email', instance.show_email) or instance.show_email - instance.show_sign = validated_data.get('show_sign', instance.show_sign) or instance.show_sign - instance.hover_or_click = validated_data.get('hover_or_click', - instance.hover_or_click) or instance.hover_or_click - instance.email_for_answer = validated_data.get('email_for_answer', - instance.email_for_answer) or instance.email_for_answer + + if validated_data.get('show_email', instance.show_email) != instance.show_email: + instance.show_email = validated_data.get('show_email', instance.show_email) + if validated_data.get('show_sign', instance.show_sign) != instance.show_sign: + instance.show_sign = validated_data.get('show_sign', instance.show_sign) + if validated_data.get('hover_or_click', instance.hover_or_click) != instance.hover_or_click: + instance.hover_or_click = validated_data.get('hover_or_click', instance.hover_or_click) + if validated_data.get('email_for_answer', instance.email_for_answer) != instance.email_for_answer: + instance.email_for_answer = validated_data.get('email_for_answer', instance.email_for_answer) instance.user.save() instance.save() return instance diff --git a/zds/member/api/tests.py b/zds/member/api/tests.py index f7cd4cddab..39c981776c 100644 --- a/zds/member/api/tests.py +++ b/zds/member/api/tests.py @@ -539,6 +539,13 @@ def test_update_member_details_show_email(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data.get('show_email'), data.get('show_email')) + data = { + 'show_email': False + } + response = self.client_authenticated.put(reverse('api-member-detail', args=[self.profile.pk]), data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data.get('show_email'), data.get('show_email')) + def test_update_member_details_show_sign(self): """ Updates show sign of a member given. @@ -550,6 +557,13 @@ def test_update_member_details_show_sign(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data.get('show_sign'), data.get('show_sign')) + data = { + 'show_sign': False + } + response = self.client_authenticated.put(reverse('api-member-detail', args=[self.profile.pk]), data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data.get('show_email'), data.get('show_email')) + def test_update_member_details_hover_or_click(self): """ Updates hover or click of a member given. @@ -561,6 +575,13 @@ def test_update_member_details_hover_or_click(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data.get('hover_or_click'), data.get('hover_or_click')) + data = { + 'hover_or_click': False + } + response = self.client_authenticated.put(reverse('api-member-detail', args=[self.profile.pk]), data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data.get('hover_or_click'), data.get('hover_or_click')) + def test_update_member_details_email_for_answer(self): """ Updates email for answer of a member given. @@ -572,6 +593,13 @@ def test_update_member_details_email_for_answer(self): self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data.get('email_for_answer'), data.get('email_for_answer')) + data = { + 'email_for_answer': False + } + response = self.client_authenticated.put(reverse('api-member-detail', args=[self.profile.pk]), data) + self.assertEqual(response.status_code, status.HTTP_200_OK) + self.assertEqual(response.data.get('email_for_answer'), data.get('email_for_answer')) + def test_member_detail_url_with_post_method(self): """ Gets an error when the user try to make a request with a method not allowed.