Coverage for sm / test_social.py: 100%
25 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 12:43 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-03-24 12:43 +0000
1from django.test import TestCase
2from django.template import Context, Template
3from django.contrib.auth import get_user_model
4from django.test import Client
6import unittest
7from django.conf import settings
10@unittest.skipIf(
11 not getattr(settings, "SOCIALACCOUNT_ENABLED", False),
12 "Social auth is disabled",
13)
14class SocialAuthTestCase(TestCase):
15 def setUp(self):
16 from django.contrib.sites.models import Site
17 from allauth.socialaccount.models import SocialApp
19 self.user = get_user_model().objects.create_user(
20 username="testuser", password="password123"
21 )
22 # site = Site.objects.get_current()
23 # Site.objects.get_current() might fail in some test envs
24 # if SITE_ID is not matched
25 site, _ = Site.objects.get_or_create(
26 id=1, defaults={"domain": "example.com", "name": "example.com"}
27 )
28 app, _ = SocialApp.objects.get_or_create(
29 provider="google",
30 defaults={"name": "Google", "client_id": "12345", "secret": "67890"},
31 )
32 app.sites.add(site)
34 def test_load(self):
35 # Allauth doesn't have social_tags, it uses socialaccount tags
36 template_str = "{% load socialaccount %}"
37 rendered = Template(template_str).render(Context({}))
38 self.assertEqual(rendered, "")
40 def test_can_connect(self):
41 c = Client()
42 c.force_login(self.user)
43 # Allauth social accounts list
44 r = c.get("/accounts/3rdparty/")
45 self.assertEqual(200, r.status_code)
46 # Check if google login link is present
47 self.assertContains(r, "google")