Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
[fix bug 765746] Keep username in profile form.
Browse files Browse the repository at this point in the history
- 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
James Socol committed Jun 20, 2012
1 parent ffc7013 commit 1c9d0a5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
5 changes: 2 additions & 3 deletions apps/phonebook/forms.py
Expand Up @@ -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' %
Expand Down
19 changes: 18 additions & 1 deletion 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):
Expand All @@ -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'])
1 change: 1 addition & 0 deletions apps/phonebook/views.py
Expand Up @@ -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,
Expand Down

0 comments on commit 1c9d0a5

Please sign in to comment.