| 1 |
from http import HTTPStatus |
| 2 |
|
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from allauth.socialaccount.providers.salesforce.provider import SalesforceProvider |
| 6 |
from tests.apps.socialaccount.base import OAuth2TestsMixin |
| 7 |
from tests.mocking import MockedResponse |
| 8 |
|
| 9 |
|
| 10 |
class SalesforceTests(OAuth2TestsMixin, TestCase): |
| 11 |
provider_id = SalesforceProvider.id |
| 12 |
|
| 13 |
def get_mocked_response( |
| 14 |
self, |
| 15 |
last_name="Penners", |
| 16 |
first_name="Raymond", |
| 17 |
name="Raymond Penners", |
| 18 |
email="[email protected]", |
| 19 |
verified_email=True, |
| 20 |
): |
| 21 |
userinfo = USERINFO_RESPONSE.format( |
| 22 |
org_id="00Dxx00000000000A0", |
| 23 |
user_id="005xx000000aWwRQAU", |
| 24 |
vip="https://test.salesforce.com", |
| 25 |
nickname="test-ooi2xhmjteep", |
| 26 |
first_name=first_name, |
| 27 |
last_name=last_name, |
| 28 |
my_domain="https://fun.cs46.my.salesforce.com", |
| 29 |
content_domain="https://fun--c.cs46.content.force.com", |
| 30 |
verified_email=repr(verified_email).lower(), |
| 31 |
email=email, |
| 32 |
active="true", |
| 33 |
is_app_installed="true", |
| 34 |
) |
| 35 |
return MockedResponse(HTTPStatus.OK, userinfo) |
| 36 |
|
| 37 |
def get_expected_to_str(self): |
| 38 |
return "[email protected]" |
| 39 |
|
| 40 |
|
| 41 |
USERINFO_RESPONSE = """ |
| 42 |
{{ |
| 43 |
"sub": "{vip}/id/{org_id}/{user_id}", |
| 44 |
"user_id": "{user_id}", |
| 45 |
"organization_id": "{org_id}", |
| 46 |
"preferred_username": "{nickname}@sample_-_dev_workspace.net", |
| 47 |
"nickname": "{nickname}", |
| 48 |
"name": "{first_name} {last_name}", |
| 49 |
"email": "{email}", |
| 50 |
"email_verified": {verified_email}, |
| 51 |
"given_name": "{first_name}", |
| 52 |
"family_name": "{last_name}", |
| 53 |
"zoneinfo": "America/Los_Angeles", |
| 54 |
"photos": {{ |
| 55 |
"picture": "{content_domain}/profilephoto/005/F", |
| 56 |
"thumbnail": "{content_domain}/profilephoto/005/T" |
| 57 |
}}, |
| 58 |
"profile": "{my_domain}/{user_id}", |
| 59 |
"picture": "{content_domain}/profilephoto/005/F", |
| 60 |
"address": {{"country": "US"}}, |
| 61 |
"urls": {{"custom_domain": "{my_domain}"}}, |
| 62 |
"active": {active}, |
| 63 |
"user_type": "STANDARD", |
| 64 |
"language": "en_US", |
| 65 |
"locale": "en_US", |
| 66 |
"utcOffset": -28800000, |
| 67 |
"updated_at": "2017-10-05T20:39:02.000+0000", |
| 68 |
"is_app_installed": {is_app_installed} |
| 69 |
}} |
| 70 |
""" |