mirror of
https://github.com/haiwen/seahub.git
synced 2025-10-21 02:42:26 +00:00
Userinfo contactemail (#1894)
* Show contact_email on user profile I think it would be good to have the edit functionality for that attribute, too, but I did not implement that right now. It's marked with TODO though. * update api and tests * review
This commit is contained in:
@@ -6,7 +6,8 @@ from tests.common.utils import randstring
|
||||
from django.core.urlresolvers import reverse
|
||||
from seahub.constants import DEFAULT_USER, GUEST_USER
|
||||
from seahub.test_utils import BaseTestCase
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname
|
||||
from seahub.base.templatetags.seahub_tags import email2nickname, \
|
||||
email2contact_email
|
||||
from seahub.profile.models import DetailedProfile
|
||||
from seahub.utils.file_size import get_file_size_unit
|
||||
|
||||
@@ -243,6 +244,33 @@ class AdminUserTest(BaseTestCase):
|
||||
|
||||
assert email2nickname(self.tmp_email) == tmp_name
|
||||
|
||||
def test_update_contact_email(self):
|
||||
|
||||
self.login_as(self.admin)
|
||||
|
||||
# change user name
|
||||
tmp_email = randstring(10) + '@seafile.test'
|
||||
data = {'contact_email': tmp_email}
|
||||
resp = self.client.put(self.url, json.dumps(data),
|
||||
'application/json')
|
||||
json_resp = json.loads(resp.content)
|
||||
self.assertEqual(200, resp.status_code)
|
||||
assert json_resp['contact_email'] == tmp_email
|
||||
|
||||
assert email2contact_email(self.tmp_email) == tmp_email
|
||||
|
||||
def test_update_contact_email_with_invalid(self):
|
||||
self.login_as(self.admin)
|
||||
|
||||
# change user name
|
||||
tmp_email = randstring(10)
|
||||
data = {'contact_email': tmp_email}
|
||||
resp = self.client.put(self.url, json.dumps(data),
|
||||
'application/json')
|
||||
json_resp = json.loads(resp.content)
|
||||
self.assertEqual(400, resp.status_code)
|
||||
|
||||
|
||||
def test_update_department(self):
|
||||
|
||||
self.login_as(self.admin)
|
||||
|
@@ -21,14 +21,14 @@ class Email2nicknameTest(BaseTestCase):
|
||||
def test_nickname_is_space(self):
|
||||
Profile.objects.add_or_update(self.user.username, ' ')
|
||||
assert len(Profile.objects.all()) == 1
|
||||
assert Profile.objects.all()[0].nickname == ' '
|
||||
assert Profile.objects.all()[0].nickname == ''
|
||||
|
||||
assert email2nickname(self.user.username) == self.user.username.split('@')[0]
|
||||
|
||||
def test_nickname_contains_space(self):
|
||||
Profile.objects.add_or_update(self.user.username, ' foo bar ')
|
||||
assert len(Profile.objects.all()) == 1
|
||||
assert Profile.objects.all()[0].nickname == ' foo bar '
|
||||
assert Profile.objects.all()[0].nickname == 'foo bar'
|
||||
|
||||
assert email2nickname(self.user.username) == 'foo bar'
|
||||
|
||||
|
@@ -19,3 +19,111 @@ class ProfileManagerTest(BaseTestCase):
|
||||
p.contact_email = 'contact@foo.com'
|
||||
p.save()
|
||||
assert 'contact@foo.com' == Profile.objects.get_contact_email_by_user(username)
|
||||
|
||||
def test_add_or_update(self):
|
||||
username = self.user.username
|
||||
profiles = Profile.objects.filter(user=username)
|
||||
for profile in profiles:
|
||||
profile.delete()
|
||||
|
||||
profile = Profile.objects.add_or_update(username, 'nickname',
|
||||
intro='hello', lang_code='ch',
|
||||
login_id=username,
|
||||
contact_email=username,
|
||||
institution='test')
|
||||
assert profile.nickname == 'nickname'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'hello'
|
||||
assert profile.lang_code == 'ch'
|
||||
assert profile.login_id == username
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
# test whether other will be changed when some one updated
|
||||
profile = Profile.objects.add_or_update(username, 'nick')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'hello'
|
||||
assert profile.lang_code == 'ch'
|
||||
assert profile.login_id == username
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, intro='intro')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'intro'
|
||||
assert profile.lang_code == 'ch'
|
||||
assert profile.login_id == username
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, lang_code='en')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'intro'
|
||||
assert profile.lang_code == 'en'
|
||||
assert profile.login_id == username
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, login_id='test@test.com')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'intro'
|
||||
assert profile.lang_code == 'en'
|
||||
assert profile.login_id == 'test@test.com'
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, contact_email='test@contact.com')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'intro'
|
||||
assert profile.lang_code == 'en'
|
||||
assert profile.login_id == 'test@test.com'
|
||||
assert profile.contact_email == 'test@contact.com'
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, institution='insti')
|
||||
assert profile.nickname == 'nick'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'intro'
|
||||
assert profile.lang_code == 'en'
|
||||
assert profile.login_id == 'test@test.com'
|
||||
assert profile.contact_email == 'test@contact.com'
|
||||
assert profile.institution == 'insti'
|
||||
|
||||
def test_add_or_update_with_empty(self):
|
||||
username = self.user.username
|
||||
profiles = Profile.objects.filter(user=username)
|
||||
for profile in profiles:
|
||||
profile.delete()
|
||||
|
||||
profile = Profile.objects.add_or_update(username, 'nickname',
|
||||
intro='hello', lang_code='ch',
|
||||
login_id=username,
|
||||
contact_email=username,
|
||||
institution='test')
|
||||
assert profile.nickname == 'nickname'
|
||||
assert profile.user == username
|
||||
assert profile.intro == 'hello'
|
||||
assert profile.lang_code == 'ch'
|
||||
assert profile.login_id == username
|
||||
assert profile.contact_email == username
|
||||
assert profile.institution == 'test'
|
||||
|
||||
profile = Profile.objects.add_or_update(username, '')
|
||||
assert profile.nickname == ''
|
||||
|
||||
profile = Profile.objects.add_or_update(username, intro='')
|
||||
assert profile.intro == ''
|
||||
|
||||
profile = Profile.objects.add_or_update(username, lang_code='')
|
||||
assert profile.lang_code == ''
|
||||
|
||||
profile = Profile.objects.add_or_update(username, login_id='')
|
||||
assert profile.login_id == ''
|
||||
|
||||
profile = Profile.objects.add_or_update(username, contact_email='')
|
||||
assert profile.contact_email == ''
|
||||
|
Reference in New Issue
Block a user