| 1 |
from django.contrib.auth import get_user_model |
| 2 |
from django.test import TestCase |
| 3 |
from django.test.utils import override_settings |
| 4 |
|
| 5 |
from allauth.socialaccount.models import SocialAccount |
| 6 |
|
| 7 |
|
| 8 |
class UtilTests(TestCase): |
| 9 |
def test_social_account_str_default(self): |
| 10 |
User = get_user_model() |
| 11 |
user = User(username="test") |
| 12 |
sa = SocialAccount(user=user) |
| 13 |
self.assertEqual("test", str(sa)) |
| 14 |
|
| 15 |
def socialaccount_str_custom_formatter(socialaccount): |
| 16 |
return f"A custom str builder for {socialaccount.user}" |
| 17 |
|
| 18 |
@override_settings( |
| 19 |
SOCIALACCOUNT_SOCIALACCOUNT_STR=socialaccount_str_custom_formatter |
| 20 |
) |
| 21 |
def test_social_account_str_customized(self): |
| 22 |
User = get_user_model() |
| 23 |
user = User(username="test") |
| 24 |
sa = SocialAccount(user=user) |
| 25 |
self.assertEqual("A custom str builder for test", str(sa)) |