Debian Codegraph @

tests/apps/socialaccount/providers/orcid/tests.py

raw
1 from http import HTTPStatus
2
3 from django.test import TestCase
4
5 from allauth.socialaccount.providers.orcid.provider import OrcidProvider
6 from tests.apps.socialaccount.base import OAuth2TestsMixin
7 from tests.mocking import MockedResponse
8
9
10 class OrcidTests(OAuth2TestsMixin, TestCase):
11 provider_id = OrcidProvider.id
12
13 def get_mocked_response(self):
14 return MockedResponse(
15 HTTPStatus.OK,
16 """
17 {
18 "orcid-identifier": {
19 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
20 "path": "0000-0001-6796-198X",
21 "host": "sandbox.orcid.org"
22 },
23 "preferences": {
24 "locale": "EN"
25 },
26 "history": {
27 "creation-method": "MEMBER_REFERRED",
28 "completion-date": null,
29 "submission-date": {
30 "value": 1456951327337
31 },
32 "last-modified-date": {
33 "value": 1519493486728
34 },
35 "claimed": true,
36 "source": null,
37 "deactivation-date": null,
38 "verified-email": true,
39 "verified-primary-email": true
40 },
41 "person": {
42 "last-modified-date": {
43 "value": 1519493469738
44 },
45 "name": {
46 "created-date": {
47 "value": 1460669254582
48 },
49 "last-modified-date": {
50 "value": 1460669254582
51 },
52 "given-names": {
53 "value": "Patricia"
54 },
55 "family-name": {
56 "value": "Lawrence"
57 },
58 "credit-name": null,
59 "source": null,
60 "visibility": "PUBLIC",
61 "path": "0000-0001-6796-198X"
62 },
63 "other-names": {
64 "last-modified-date": null,
65 "other-name": [],
66 "path": "/0000-0001-6796-198X/other-names"
67 },
68 "biography": {
69 "created-date": {
70 "value": 1460669254583
71 },
72 "last-modified-date": {
73 "value": 1460669254583
74 },
75 "content": null,
76 "visibility": "PUBLIC",
77 "path": "/0000-0001-6796-198X/biography"
78 },
79 "researcher-urls": {
80 "last-modified-date": null,
81 "researcher-url": [],
82 "path": "/0000-0001-6796-198X/researcher-urls"
83 },
84 "emails": {
85 "last-modified-date": {
86 "value": 1519493469738
87 },
88 "email": [
89 {
90 "created-date": {
91 "value": 1456951327661
92 },
93 "last-modified-date": {
94 "value": 1519493469738
95 },
96 "source": {
97 "source-orcid": {
98 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
99 "path": "0000-0001-6796-198X",
100 "host": "sandbox.orcid.org"
101 },
102 "source-client-id": null,
103 "source-name": {
104 "value": "Patricia Lawrence"
105 }
106 },
107 "email": "[email protected]",
108 "path": null,
109 "visibility": "PUBLIC",
110 "verified": true,
111 "primary": true,
112 "put-code": null
113 }
114 ],
115 "path": "/0000-0001-6796-198X/email"
116 },
117 "addresses": {
118 "last-modified-date": null,
119 "address": [],
120 "path": "/0000-0001-6796-198X/address"
121 },
122 "keywords": {
123 "last-modified-date": null,
124 "keyword": [],
125 "path": "/0000-0001-6796-198X/keywords"
126 },
127 "external-identifiers": {
128 "last-modified-date": null,
129 "external-identifier": [],
130 "path": "/0000-0001-6796-198X/external-identifiers"
131 },
132 "path": "/0000-0001-6796-198X/person"
133 },
134 "activities-summary": {
135 "last-modified-date": {
136 "value": 1513777479628
137 },
138 "educations": {
139 "last-modified-date": {
140 "value": 1459957293365
141 },
142 "education-summary": [
143 {
144 "created-date": {
145 "value": 1459957293365
146 },
147 "last-modified-date": {
148 "value": 1459957293365
149 },
150 "source": {
151 "source-orcid": {
152 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
153 "path": "0000-0001-6796-198X",
154 "host": "sandbox.orcid.org"
155 },
156 "source-client-id": null,
157 "source-name": {
158 "value": "Patricia Lawrence"
159 }
160 },
161 "department-name": null,
162 "role-title": null,
163 "start-date": null,
164 "end-date": null,
165 "organization": {
166 "name": "Polytech'Rambouillet",
167 "address": {
168 "city": "Rambouillet",
169 "region": null,
170 "country": "FR"
171 },
172 "disambiguated-organization": null
173 },
174 "visibility": "PUBLIC",
175 "put-code": 19996,
176 "path": "/0000-0001-6796-198X/education/19996"
177 }
178 ],
179 "path": "/0000-0001-6796-198X/educations"
180 },
181 "employments": {
182 "last-modified-date": {
183 "value": 1513777479628
184 },
185 "employment-summary": [
186 {
187 "created-date": {
188 "value": 1510399314937
189 },
190 "last-modified-date": {
191 "value": 1513777479628
192 },
193 "source": {
194 "source-orcid": {
195 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
196 "path": "0000-0001-6796-198X",
197 "host": "sandbox.orcid.org"
198 },
199 "source-client-id": null,
200 "source-name": {
201 "value": "Patricia Lawrence"
202 }
203 },
204 "department-name": null,
205 "role-title": null,
206 "start-date": {
207 "year": {
208 "value": "2015"
209 },
210 "month": {
211 "value": "03"
212 },
213 "day": {
214 "value": "02"
215 }
216 },
217 "end-date": null,
218 "organization": {
219 "name": "École nationale supérieure de céramique industrielle",
220 "address": {
221 "city": "Limoges",
222 "region": null,
223 "country": "FR"
224 },
225 "disambiguated-organization": {
226 "disambiguated-organization-identifier": "105362",
227 "disambiguation-source": "RINGGOLD"
228 }
229 },
230 "visibility": "PUBLIC",
231 "put-code": 29138,
232 "path": "/0000-0001-6796-198X/employment/29138"
233 },
234 {
235 "created-date": {
236 "value": 1502366640610
237 },
238 "last-modified-date": {
239 "value": 1513777467282
240 },
241 "source": {
242 "source-orcid": {
243 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
244 "path": "0000-0001-6796-198X",
245 "host": "sandbox.orcid.org"
246 },
247 "source-client-id": null,
248 "source-name": {
249 "value": "Patricia Lawrence"
250 }
251 },
252 "department-name": null,
253 "role-title": null,
254 "start-date": {
255 "year": {
256 "value": "2002"
257 },
258 "month": {
259 "value": "02"
260 },
261 "day": {
262 "value": "16"
263 }
264 },
265 "end-date": {
266 "year": {
267 "value": "2015"
268 },
269 "month": {
270 "value": "08"
271 },
272 "day": {
273 "value": "12"
274 }
275 },
276 "organization": {
277 "name": "University of Cambridge",
278 "address": {
279 "city": "Cambridge",
280 "region": "Cambridgeshire",
281 "country": "GB"
282 },
283 "disambiguated-organization": {
284 "disambiguated-organization-identifier": "2152",
285 "disambiguation-source": "RINGGOLD"
286 }
287 },
288 "visibility": "PUBLIC",
289 "put-code": 27562,
290 "path": "/0000-0001-6796-198X/employment/27562"
291 }
292 ],
293 "path": "/0000-0001-6796-198X/employments"
294 },
295 "fundings": {
296 "last-modified-date": null,
297 "group": [],
298 "path": "/0000-0001-6796-198X/fundings"
299 },
300 "peer-reviews": {
301 "last-modified-date": null,
302 "group": [],
303 "path": "/0000-0001-6796-198X/peer-reviews"
304 },
305 "works": {
306 "last-modified-date": {
307 "value": 1459957753077
308 },
309 "group": [
310 {
311 "last-modified-date": {
312 "value": 1459957753077
313 },
314 "external-ids": {
315 "external-id": []
316 },
317 "work-summary": [
318 {
319 "put-code": 583440,
320 "created-date": {
321 "value": 1459957753047
322 },
323 "last-modified-date": {
324 "value": 1459957753077
325 },
326 "source": {
327 "source-orcid": {
328 "uri": "https://sandbox.orcid.org/0000-0001-6796-198X",
329 "path": "0000-0001-6796-198X",
330 "host": "sandbox.orcid.org"
331 },
332 "source-client-id": null,
333 "source-name": {
334 "value": "Patricia Lawrence"
335 }
336 },
337 "title": {
338 "title": {
339 "value": "Standard & Poor's fiscal methodology reviewed"
340 },
341 "subtitle": null,
342 "translated-title": null
343 },
344 "external-ids": {
345 "external-id": []
346 },
347 "type": "JOURNAL_ARTICLE",
348 "publication-date": {
349 "year": {
350 "value": "2001"
351 },
352 "month": {
353 "value": "07"
354 },
355 "day": {
356 "value": "14"
357 },
358 "media-type": null
359 },
360 "visibility": "PUBLIC",
361 "path": "/0000-0001-6796-198X/work/583440",
362 "display-index": "0"
363 }
364 ]
365 }
366 ],
367 "path": "/0000-0001-6796-198X/works"
368 },
369 "path": "/0000-0001-6796-198X/activities"
370 },
371 "path": "/0000-0001-6796-198X"
372 }
373 """,
374 )
375
376 def get_expected_to_str(self):
377 return "Orcid.org"
378
379 def get_login_response_json(self, with_refresh_token=True):
380 # TODO: This is not an actual response. I added this in order
381 # to get the test suite going but did not verify to check the
382 # exact response being returned.
383 return """
384 {
385 "access_token": "testac",
386 "expires_in": 631138026,
387 "token_type": "bearer",
388 "orcid": "0000-0001-6796-198X",
389 "scope": "/orcid-profile/read-limited",
390 "refresh_token": "testrf"
391 }"""