Skip to content

Commit

Permalink
Merge pull request #73 from fga-gpp-mds/BF02-ArrumarBugDaEdicaoDeUsuario
Browse files Browse the repository at this point in the history
Bf02 arrumar bug da edicao de usuario
  • Loading branch information
mateusdemorais committed May 17, 2018
2 parents e8524c7 9812c60 commit 529271c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 11 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 51,17 @@ def create(self, validated_data):
token.save()
return voxpopuser

def update(self, instance, validated_data):
updatedUser = vars(instance)
del(updatedUser['_state'])
for field, value in validated_data.items():
updatedUser[field] = value
updated = User(**updatedUser)
if 'password' in validated_data:
updated.set_password(validated_data['password'])
updated.save()
return updated


class ParliamentarySerializer(serializers.ModelSerializer):
class Meta:
Expand Down
7 changes: 3 additions & 4 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 66,16 @@ def test_update_user(self):
"""
self.assertEqual(self.user.username, 'teste')
data = {
'username':'updated',
'first_name':'teste',
'username':'teste',
'first_name':'updated',
'last_name':'teste',
'email':'[email protected]',
'password':'teste'
}
response = self.client.put(self.url str(self.user.pk) '/', data)

new_user = User.objects.get(pk=self.user.pk)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(new_user.username, 'updated')
self.assertEqual(new_user.first_name, data['first_name'])

def test_invalid_update_user(self):
"""
Expand Down

0 comments on commit 529271c

Please sign in to comment.