Skip to content

Commit

Permalink
bugfix(mp): update boolean field on member
Browse files Browse the repository at this point in the history
  • Loading branch information
DevHugo committed May 6, 2015
1 parent e06d249 commit 7388c25
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
15 changes: 9 additions & 6 deletions zds/member/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions zds/member/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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_sign'), data.get('show_sign'))

def test_update_member_details_hover_or_click(self):
"""
Updates hover or click of a member given.
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 7388c25

Please sign in to comment.