mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 00:26:33 +00:00
Simplifies update user view
This commit is contained in:
parent
fcce1a5a36
commit
db281d5154
2 changed files with 16 additions and 8 deletions
|
@ -6,7 +6,7 @@ from django.http.response import Http404
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.test.client import RequestFactory
|
from django.test.client import RequestFactory
|
||||||
|
|
||||||
from bookwyrm import view_actions as actions, models
|
from bookwyrm import forms, models, view_actions as actions
|
||||||
from bookwyrm.settings import DOMAIN
|
from bookwyrm.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,9 +247,9 @@ class ViewActions(TestCase):
|
||||||
'confirm-password': 'hi'
|
'confirm-password': 'hi'
|
||||||
})
|
})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
resp = actions.password_change(request)
|
with patch('bookwyrm.view_actions.login'):
|
||||||
self.assertEqual(resp.template_name, 'user.html')
|
resp = actions.password_change(request)
|
||||||
self.assertNotEqual(self.user.password, password_hash)
|
self.assertNotEqual(self.local_user.password, password_hash)
|
||||||
|
|
||||||
def test_password_change_mismatch(self):
|
def test_password_change_mismatch(self):
|
||||||
''' change password '''
|
''' change password '''
|
||||||
|
@ -260,12 +260,19 @@ class ViewActions(TestCase):
|
||||||
})
|
})
|
||||||
request.user = self.local_user
|
request.user = self.local_user
|
||||||
resp = actions.password_change(request)
|
resp = actions.password_change(request)
|
||||||
self.assertEqual(resp.template_name, 'edit_user.html')
|
self.assertEqual(self.local_user.password, password_hash)
|
||||||
self.assertEqual(self.user.password, password_hash)
|
|
||||||
|
|
||||||
|
|
||||||
def test_edit_user(self):
|
def test_edit_user(self):
|
||||||
''' use a form to update a user '''
|
''' use a form to update a user '''
|
||||||
|
form = forms.EditUserForm(instance=self.local_user)
|
||||||
|
form.data['name'] = 'New Name'
|
||||||
|
request = self.factory.post('', form.data)
|
||||||
|
request.user = self.local_user
|
||||||
|
|
||||||
|
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||||
|
actions.edit_profile(request)
|
||||||
|
self.assertEqual(self.local_user.name, 'New Name')
|
||||||
|
|
||||||
|
|
||||||
def test_switch_edition(self):
|
def test_switch_edition(self):
|
||||||
|
|
|
@ -166,7 +166,8 @@ def password_change(request):
|
||||||
@require_POST
|
@require_POST
|
||||||
def edit_profile(request):
|
def edit_profile(request):
|
||||||
''' les get fancy with images '''
|
''' les get fancy with images '''
|
||||||
form = forms.EditUserForm(request.POST, request.FILES)
|
form = forms.EditUserForm(
|
||||||
|
request.POST, request.FILES, instance=request.user)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
data = {'form': form, 'user': request.user}
|
data = {'form': form, 'user': request.user}
|
||||||
return TemplateResponse(request, 'edit_user.html', data)
|
return TemplateResponse(request, 'edit_user.html', data)
|
||||||
|
@ -201,7 +202,7 @@ def edit_profile(request):
|
||||||
user.avatar.save(filename, ContentFile(output.getvalue()))
|
user.avatar.save(filename, ContentFile(output.getvalue()))
|
||||||
user.save()
|
user.save()
|
||||||
|
|
||||||
outgoing.handle_update_user(request.user)
|
outgoing.handle_update_user(user)
|
||||||
return redirect('/user/%s' % request.user.localname)
|
return redirect('/user/%s' % request.user.localname)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue