Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[fix bug 765746] Keep username in profile form.

- Make sure that the username field in the profile form stays filled in.
- Make sure that it has the correct type.
- Add a test for both.
  • Loading branch information...
commit 1c9d0a523077a5db16f589ba100cca84b42dd838 1 parent ffc7013
James Socol authored
View
5 apps/phonebook/forms.py
@@ -39,9 +39,8 @@ def clean_limit(self):
return limit
-class UsernameWidget(forms.widgets.Input):
- type = 'text'
-
+class UsernameWidget(forms.widgets.TextInput):
+ """A TextInput with some special markup to indicate a URL."""
def render(self, *args, **kwargs):
return mark_safe(u'<span class="label-text">'
'http://mozillians.org/ </span>%s' %
View
19 apps/phonebook/tests/test_modelform.py
@@ -1,7 +1,8 @@
from funfactory.urlresolvers import reverse
from nose.tools import eq_
+from pyquery import PyQuery as pq
-from common.tests import TestCase
+from common.tests import TestCase, user
class ModelForms(TestCase):
@@ -22,3 +23,19 @@ def test_edit_unavailable_form_field(self):
newbie_profile = bad_edit.context['profile']
assert not newbie_profile.is_vouched
eq_(newbie_profile.user.first_name, bad_data['first_name'])
+
+ def test_username_filled_in(self):
+ """The username field should have a type and value."""
+ newbie = user(username='sam', email='sam@sam.com')
+
+ url = reverse('profile.edit')
+ assert self.client.login(email=newbie.email)
+ response = self.client.get(url, follow=True)
+
+ eq_(200, response.status_code)
+ doc = pq(response.content)
+ field = doc('#id_username')[0]
+ eq_('input', field.tag)
+ assert 'value' in field.attrib
+ eq_('text', field.attrib['type'])
+ eq_(newbie.username, field.attrib['value'])
View
1  apps/phonebook/views.py
@@ -98,6 +98,7 @@ def edit_profile(request):
else:
initial = dict(first_name=request.user.first_name,
last_name=request.user.last_name,
+ username=request.user.username,
bio=profile.bio,
website=profile.website,
irc_nickname=profile.ircname,
Please sign in to comment.
Something went wrong with that request. Please try again.