Skip to content

Commit

Permalink
#209 imcreasing coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Sep 3, 2014
1 parent 6845171 commit 33797e8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions djangoproject/core/tests/test_user_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#coding: utf-8
from unittest.case import skip
from django.contrib.auth.models import User
from django.test import TestCase
Expand Down Expand Up @@ -97,6 +98,36 @@ def test_change_username_name_already_taken(self):
msg = [m for m in response.context['messages']][0].message
self.assertTrue('username is already taken' in msg)

def test_change_username_name_invalid(self):
old_username = self.user.username
response = self.client.post('/user/change_username', {
'new_username': 'cannót'
})
user = User.objects.get(pk=self.user.id)
self.assertEqual(200, response.status_code)
self.assertEqual(old_username, user.username)

msg = [m for m in response.context['messages']][0].message
self.assertTrue('username is invalid' in msg)

def test_can_change_username_once_but_not_twice(self):
response = self.client.post('/user/change_username', {
'new_username': 'oreiudo'
})
self.assertEqual(200, response.status_code)
user = User.objects.get(pk=self.user.id)
self.assertEqual('oreiudo', user.username)

response = self.client.post('/user/change_username', {
'new_username': 'narigudo'
})
user = User.objects.get(pk=self.user.id)
self.assertEqual(200, response.status_code)
self.assertEqual('oreiudo', user.username)

msg = [m for m in response.context['messages']][0].message
self.assertEqual('You cannot change your username anymore.', msg)


class TestDeprecatedCoreUserViews(TestCase):

Expand Down

0 comments on commit 33797e8

Please sign in to comment.