From 93079938a3080ff66af31c005ec4d8af607ac474 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Tue, 24 Sep 2013 23:27:30 +0200 Subject: [PATCH] Fixed keyerror on user setting page Fix #891 --- openslides/participant/forms.py | 1 + tests/participant/test_views.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 96862079a..17776afb9 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -165,6 +165,7 @@ class UsersettingsForm(CssClassMixin, forms.ModelForm): language = forms.ChoiceField(choices=settings.LANGUAGES) def __init__(self, *args, **kwargs): + kwargs['initial'] = kwargs.get('initial', {}) kwargs['initial']['user_name'] = kwargs['instance'].username return super(UsersettingsForm, self).__init__(*args, **kwargs) diff --git a/tests/participant/test_views.py b/tests/participant/test_views.py index 38b81d5a1..360acb6d3 100644 --- a/tests/participant/test_views.py +++ b/tests/participant/test_views.py @@ -122,3 +122,23 @@ class LockoutProtection(TestCase): form='form', field=None, errors='You can not remove the permission to manage participants from the last group your are in.') + + +class TestUserSettings(TestCase): + def setUp(self): + self.admin = User.objects.get(pk=1) + self.admin_client = Client() + self.admin_client.login(username='admin', password='admin') + + def test_get(self): + response = self.admin_client.get('/usersettings/') + self.assertEqual(response.status_code, 200) + + def test_pst(self): + response = self.admin_client.post('/usersettings/', { + 'user_name': 'new_name', + 'language': 'de'}) + self.assertEqual(response.status_code, 200) + + admin = User.objects.get(pk=1) + self.assertEqual(admin.username, 'new_name')