-
Notifications
You must be signed in to change notification settings - Fork 87
/
test_user_profile.py
61 lines (48 loc) · 2.1 KB
/
test_user_profile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Tests for opal.models.UserProfile
"""
from django.contrib.auth.models import User
from django.test import TestCase
from mock import patch
from opal.models import UserProfile
GRAVATAR = 'http://gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?s=80&r=g&d=identicon'
GRAVATAR2 = 'http://gravatar.com/avatar/ae2b1fca515949e5d54fb22b8ed95575?s=80&r=g&d=identicon'
class UserProfileTest(TestCase):
def setUp(self):
self.user = User(
username='testing',
first_name='Test', last_name='User'
)
self.user.save()
self.profile = self.user.profile
def test_to_dict_has_full_name(self):
as_dict = self.profile.to_dict()
self.assertEqual('Test User', as_dict['full_name'])
def test_to_dict_has_avatar_url(self):
as_dict = self.profile.to_dict()
self.assertTrue('avatar_url' in as_dict)
def test_to_dict_has_id(self):
self.assertEqual(self.user.id, self.profile.to_dict()['user_id'])
def test_get_avatar_url(self):
self.profile.user.email = 'test@example.com'
self.profile.user.save()
url = self.profile.get_avatar_url()
self.assertEqual(url, GRAVATAR)
def test_get_avatar_url_uppercase_in_email(self):
self.profile.user.email = 'TEST@example.com'
self.profile.user.save()
url = self.profile.get_avatar_url()
self.assertEqual(url, GRAVATAR)
def test_get_avatar_url_uses_username_if_no_email(self):
url = self.profile.get_avatar_url()
self.assertEqual(url, GRAVATAR2)
def test_get_roles(self):
self.assertEqual({'default': []}, self.profile.get_roles())
def test_can_see_pid(self):
with patch.object(UserProfile, 'get_roles') as mock_roles:
mock_roles.return_value = dict(default=['scientist'])
self.assertEqual(False, self.profile.can_see_pid)
def test_explicit_access_only(self):
with patch.object(UserProfile, 'get_roles') as mock_roles:
mock_roles.return_value = dict(default=['scientist'])
self.assertEqual(True, self.profile.explicit_access_only)