~super-friends/friends/13.10

« back to all changes in this revision

Viewing changes to friends/tests/test_linkedin.py

  • Committer: Tarmac
  • Author(s): Robert Bruce Park
  • Date: 2013-07-22 20:34:58 UTC
  • mfrom: (224.1.12 simplify-contacts)
  • Revision ID: tarmac-20130722203458-dwbs94fsik5iydt0
Vast simplification of contact logic.

Approved by Ken VanDine, PS Jenkins bot, Robert Bruce Park.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import unittest
25
25
 
26
 
from friends.protocols.linkedin import LinkedIn
 
26
from friends.protocols.linkedin import LinkedIn, make_fullname
27
27
from friends.tests.mocks import FakeAccount, FakeSoupMessage, LogMock
28
28
from friends.tests.mocks import TestModel, mock
29
29
from friends.errors import AuthorizationError
46
46
        # as to isolate out test logger from other tests.
47
47
        self.log_mock.stop()
48
48
 
 
49
    def test_name_logic(self):
 
50
        self.assertEqual('', make_fullname())
 
51
        self.assertEqual('', make_fullname(irrelevant_key='foo'))
 
52
        self.assertEqual('Bob', make_fullname(**dict(firstName='Bob')))
 
53
        self.assertEqual('LastOnly', make_fullname(**dict(lastName='LastOnly')))
 
54
        self.assertEqual(
 
55
            'Bob Loblaw',
 
56
            make_fullname(**dict(firstName='Bob', lastName='Loblaw')))
 
57
        self.assertEqual(
 
58
            'Bob Loblaw',
 
59
            make_fullname(**dict(firstName='Bob', lastName='Loblaw',
 
60
                                 extra='ignored')))
 
61
 
49
62
    @mock.patch('friends.utils.authentication.manager')
50
63
    @mock.patch('friends.utils.authentication.Accounts')
51
64
    @mock.patch.dict('friends.utils.authentication.__dict__', LOGIN_TIMEOUT=1)
97
110
             '&authToken=-LNy&trk=api*a26127*s26893*',
98
111
             1, False, '', '', '', '', '', '', '', 0.0, 0.0])
99
112
 
100
 
    @mock.patch('friends.utils.base.Base._create_contact')
101
 
    def test_create_contact(self, base_mock):
102
 
        self.protocol._create_contact(
103
 
            dict(id='jb89', firstName='Joe', lastName='Blow'))
104
 
        base_mock.assert_called_once_with(
105
 
            'Joe Blow', None,
106
 
            {'X-URIS': '', 'linkedin-id': 'jb89', 'linkedin-name': 'Joe Blow'})
107
 
 
108
113
    @mock.patch('friends.utils.http.Soup.Message',
109
114
                FakeSoupMessage('friends.tests.data', 'linkedin_contacts.json'))
110
115
    @mock.patch('friends.protocols.linkedin.LinkedIn._login',
118
123
        self.assertEqual(
119
124
            push.mock_calls,
120
125
            [mock.call(
121
 
                {'siteStandardProfileRequest':
122
 
                 {'url': 'https://www.linkedin.com'},
123
 
                 'pictureUrl': 'http://m.c.lnkd.licdn.com',
124
 
                 'apiStandardProfileRequest':
125
 
                 {'url': 'http://api.linkedin.com',
126
 
                  'headers': {'_total': 1, 'values':
127
 
                              [{'value': 'name:', 'name': 'x-li-auth-token'}]}},
128
 
                 'industry': 'Computer Network Security',
129
 
                 'lastName': 'A',
130
 
                 'firstName': 'H',
131
 
                 'headline': 'Unix Administrator at NVIDIA',
132
 
                 'location': {'name': 'Pune Area, India',
133
 
                              'country': {'code': 'in'}},
134
 
                 'id': 'IFDI'}),
135
 
 
136
 
             mock.call(
137
 
                 {'siteStandardProfileRequest':
138
 
                  {'url': 'https://www.linkedin.com'},
139
 
                  'pictureUrl': 'http://m.c.lnkd.licdn.com',
140
 
                  'apiStandardProfileRequest':
141
 
                  {'url': 'http://api.linkedin.com',
142
 
                   'headers': {'_total': 1, 'values':
143
 
                               [{'value': 'name:', 'name': 'x-li-auth-token'}]}},
144
 
                  'industry': 'Food Production',
145
 
                  'lastName': 'A',
146
 
                  'firstName': 'C',
147
 
                  'headline': 'Recent Graduate, Simon Fraser University',
148
 
                  'location': {'name': 'Vancouver, Canada Area',
149
 
                               'country': {'code': 'ca'}},
150
 
                  'id': 'AefF'}),
151
 
 
152
 
             mock.call(
153
 
                 {'siteStandardProfileRequest':
154
 
                  {'url': 'https://www.linkedin.com'},
155
 
                  'pictureUrl': 'http://m.c.lnkd.licdn.com',
156
 
                  'apiStandardProfileRequest':
157
 
                  {'url': 'http://api.linkedin.com',
158
 
                   'headers': {'_total': 1, 'values':
159
 
                               [{'value': 'name:', 'name': 'x-li-auth-token'}]}},
160
 
                  'industry': 'Computer Software',
161
 
                  'lastName': 'A',
162
 
                  'firstName': 'R',
163
 
                  'headline': 'Technical Lead at Canonical Ltd.',
164
 
                  'location': {'name': 'Auckland, New Zealand',
165
 
                               'country': {'code': 'nz'}},
166
 
                  'id': 'DFdV'}),
167
 
 
168
 
             mock.call(
169
 
                 {'siteStandardProfileRequest':
170
 
                  {'url': 'https://www.linkedin.com'},
171
 
                  'pictureUrl': 'http://m.c.lnkd.licdn.com',
172
 
                  'apiStandardProfileRequest':
173
 
                  {'url': 'http://api.linkedin.com',
174
 
                   'headers': {'_total': 1, 'values':
175
 
                               [{'value': 'name:', 'name': 'x-li-auth-token'}]}},
176
 
                  'industry': 'Photography',
177
 
                  'lastName': 'Z',
178
 
                  'firstName': 'A',
179
 
                  'headline': 'Sales manager at McBain Camera',
180
 
                  'location': {'name': 'Edmonton, Canada Area',
181
 
                               'country': {'code': 'ca'}},
182
 
                  'id': 'xkBU'})])
 
126
                {'X-URIS': 'https://www.linkedin.com',
 
127
                 'X-FOLKS-WEB-SERVICES-IDS': {
 
128
                     'linkedin-id': 'IFDI',
 
129
                     'remote-full-name': 'H A'},
 
130
                 'linkedin-name': 'H A',
 
131
                 'linkedin-id': 'IFDI'}),
 
132
             mock.call(
 
133
                 {'X-URIS': 'https://www.linkedin.com',
 
134
                  'X-FOLKS-WEB-SERVICES-IDS': {
 
135
                      'linkedin-id': 'AefF',
 
136
                      'remote-full-name': 'C A'},
 
137
                  'linkedin-name': 'C A',
 
138
                  'linkedin-id': 'AefF'}),
 
139
             mock.call(
 
140
                 {'X-URIS': 'https://www.linkedin.com',
 
141
                  'X-FOLKS-WEB-SERVICES-IDS': {
 
142
                      'linkedin-id': 'DFdV',
 
143
                      'remote-full-name': 'R A'},
 
144
                  'linkedin-name': 'R A',
 
145
                  'linkedin-id': 'DFdV'}),
 
146
             mock.call(
 
147
                 {'X-URIS': 'https://www.linkedin.com',
 
148
                  'X-FOLKS-WEB-SERVICES-IDS': {
 
149
                      'linkedin-id': 'xkBU',
 
150
                      'remote-full-name': 'A Z'},
 
151
                  'linkedin-name': 'A Z',
 
152
                  'linkedin-id': 'xkBU'})])