| 1 |
from http import HTTPStatus |
| 2 |
|
| 3 |
from django.test import TestCase |
| 4 |
|
| 5 |
from allauth.socialaccount.models import SocialAccount |
| 6 |
from allauth.socialaccount.providers.openstreetmap.provider import OpenStreetMapProvider |
| 7 |
from tests.apps.socialaccount.base import OAuthTestsMixin |
| 8 |
from tests.mocking import MockedResponse |
| 9 |
|
| 10 |
|
| 11 |
class OpenStreetMapTests(OAuthTestsMixin, TestCase): |
| 12 |
provider_id = OpenStreetMapProvider.id |
| 13 |
|
| 14 |
def get_mocked_response(self): |
| 15 |
return [ |
| 16 |
MockedResponse( |
| 17 |
HTTPStatus.OK, |
| 18 |
r""" |
| 19 |
{ |
| 20 |
"version": "0.6", |
| 21 |
"generator": "OpenStreetMap server", |
| 22 |
"copyright": "OpenStreetMap and contributors", |
| 23 |
"attribution": "http://www.openstreetmap.org/copyright", |
| 24 |
"license": "http://opendatacommons.org/licenses/odbl/1-0/", |
| 25 |
"user": { |
| 26 |
"id": 1, |
| 27 |
"display_name": "Steve", |
| 28 |
"account_created": "2024-11-06T20:11:01Z", |
| 29 |
"description": "", |
| 30 |
"contributor_terms": { |
| 31 |
"agreed": true, |
| 32 |
"pd": true |
| 33 |
}, |
| 34 |
"img": { |
| 35 |
"href": "https://secure.gravatar.com/avatar.jpg" |
| 36 |
}, |
| 37 |
"roles": [], |
| 38 |
"changesets": { |
| 39 |
"count": 0 |
| 40 |
}, |
| 41 |
"traces": { |
| 42 |
"count": 0 |
| 43 |
}, |
| 44 |
"blocks": { |
| 45 |
"received": { |
| 46 |
"count": 0, |
| 47 |
"active": 0 |
| 48 |
} |
| 49 |
}, |
| 50 |
"languages": [ |
| 51 |
"en-US", |
| 52 |
"en" |
| 53 |
], |
| 54 |
"messages": { |
| 55 |
"received": { |
| 56 |
"count": 0, |
| 57 |
"unread": 0 |
| 58 |
}, |
| 59 |
"sent": { |
| 60 |
"count": 0 |
| 61 |
} |
| 62 |
} |
| 63 |
} |
| 64 |
} |
| 65 |
""", |
| 66 |
) |
| 67 |
] # noqa |
| 68 |
|
| 69 |
def get_expected_to_str(self): |
| 70 |
return "Steve" |
| 71 |
|
| 72 |
def test_login(self): |
| 73 |
super().test_login() |
| 74 |
account = SocialAccount.objects.get(uid="1") |
| 75 |
osm_account = account.get_provider_account() |
| 76 |
self.assertEqual(osm_account.get_username(), "Steve") |
| 77 |
self.assertEqual( |
| 78 |
osm_account.get_avatar_url(), |
| 79 |
"https://secure.gravatar.com/avatar.jpg", |
| 80 |
) |
| 81 |
self.assertEqual( |
| 82 |
osm_account.get_profile_url(), |
| 83 |
"https://www.openstreetmap.org/user/Steve", |
| 84 |
) |
| 85 |
self.assertEqual(osm_account.to_str(), "Steve") |