Skip to content

Commit

Permalink
#209 fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tonylampada committed Sep 3, 2014
1 parent 5f4cce0 commit 6845171
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
1 change: 0 additions & 1 deletion djangoproject/core/services/user_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def change_username(user, new_username):
subject = 'user %s changed username %s --> %s' % (user.id, old_username, new_username)
body = '<a href="http://freedomsponsors.org/user/%s">%s</a>' % (user.id, new_username)
mail_services.notify_admin(subject, body)
return True


def get_users_list():
Expand Down
3 changes: 3 additions & 0 deletions djangoproject/core/tests/helpers/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def createDummyUserRandom(login, password):
user = User.objects.create_user(random_login, random_login+'@gogogo.com', password)
userinfo = UserInfo.newUserInfo(user)
userinfo.realName = login+' Real'
userinfo.date_last_updated = timezone.now()
userinfo.save()
return user

Expand All @@ -22,6 +23,7 @@ def create_dummy_sponsor():
user = User.objects.create_user('userone_%s'%randomnum, 'userone_%[email protected]'%randomnum, 'abcdef')
userinfo = UserInfo.newUserInfo(user)
userinfo.realName = 'User One'
userinfo.date_last_updated = timezone.now()
userinfo.save()
return user

Expand All @@ -30,6 +32,7 @@ def create_dummy_programmer():
user = User.objects.create_user('usertwo_%s'%randomnum, 'usertwo_%[email protected]'%randomnum, 'abcdef')
userinfo = UserInfo.newUserInfo(user)
userinfo.realName = 'User Two'
userinfo.date_last_updated = timezone.now()
userinfo.save()
return user

Expand Down
17 changes: 10 additions & 7 deletions djangoproject/core/tests/test_user_services.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.contrib.auth.models import User
from django.test import TestCase
from core.models import Watch, Offer, Solution
from core.services import watch_services, user_services
from core.services import watch_services, user_services, FSException
from core.tests.helpers import test_data


Expand Down Expand Up @@ -37,14 +37,17 @@ def test_deactivated_user_should_not_be_sponsoring_working_or_watching(self):
def test_change_username(self):
user = test_data.create_dummy_sponsor()

change_ok = user_services.change_username(user, 'oreiudo')
user_services.change_username(user, 'oreiudo')
user = User.objects.get(pk=user.id)

self.assertTrue(change_ok)
self.assertEqual('oreiudo', user.username)

user2 = test_data.create_dummy_sponsor()
change_ok = user_services.change_username(user2, 'oreiudo')

self.assertFalse(change_ok)
deupau = False
try:
user_services.change_username(user2, 'oreiudo')
except FSException as e:
deupau = True
self.assertTrue('already taken' in e.message)
self.assertTrue(deupau)
user2 = User.objects.get(pk=user2.id)
self.assertNotEqual('oreiudo', user2.username)
19 changes: 10 additions & 9 deletions djangoproject/core/tests/test_user_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ def test_list_users(self):
self.assertEqual(2, len(response.context['users']))

def test_view_user(self):
response = self.client.get('/user/%d/' % self.user.id)
response = self.client.get('/user/%s/' % self.user.username)
self.assertTemplateUsed(response, 'core2/user.html')
self.assertEqual(self.user, response.context['le_user'])

def test_view_user_with_slug(self):
response = self.client.get('/user/%d/%s' % (self.user.id, self.user.username))
response = self.client.get('/user/%d/%s' % (self.user.id, self.user.username), follow=True)
self.assertTemplateUsed(response, 'core2/user.html')
self.assertTrue('http://testserver/user/%s/' % self.user.username, response.redirect_chain[-1][0])
self.assertEqual(self.user, response.context['le_user'])

def test_view_edit_form(self):
Expand All @@ -64,7 +65,6 @@ def test_view_edit_form(self):

def test_view_edit_submit(self):
response = self.client.post('/user/edit/submit', {
'screenName': 'John Doe',
'website': 'http://www.test.com',
'about': 'A placeholder user.',
'realName': 'John Doe',
Expand All @@ -75,10 +75,8 @@ def test_view_edit_submit(self):
redirect_url = response.redirect_chain[0][0]
redirect_status = response.redirect_chain[0][1]
self.assertEqual(302, redirect_status)
self.assertTrue(redirect_url.startswith('http://testserver/user/'))
self.assertTrue(redirect_url.endswith('/john-doe?prim=true'))
self.assertEqual('http://testserver/user/%s?prim=true' % self.user.username, redirect_url)

@skip('TODO')
def test_change_username_ok(self):
response = self.client.post('/user/change_username', {
'new_username': 'oreiudo'
Expand All @@ -87,7 +85,6 @@ def test_change_username_ok(self):
self.assertEqual(200, response.status_code)
self.assertEqual('oreiudo', user.username)

@skip('TODO')
def test_change_username_name_already_taken(self):
old_username = self.user.username
response = self.client.post('/user/change_username', {
Expand All @@ -113,11 +110,15 @@ def _assert_redirect(self, url):
expected = [('http://testserver' + url, 301)]
self.assertEqual(expected, response.redirect_chain)

def _assert_redirect_to_user(self, url):
response = self.client.get('/core' + url, follow=True)
self.assertTrue('http://testserver/user/%s/' % self.user.username, response.redirect_chain[-1][0])

def test_list_users(self):
self._assert_redirect('/user/')

def test_view_user(self):
self._assert_redirect('/user/%d/' % self.user.id)
self._assert_redirect_to_user('/user/%d/' % self.user.id)

def test_view_user_with_slug(self):
self._assert_redirect('/user/%d/%s' % (self.user.id, self.user.username))
self._assert_redirect_to_user('/user/%d/%s' % (self.user.id, self.user.username))

0 comments on commit 6845171

Please sign in to comment.