Debian Codegraph @

tests/apps/headless/socialaccount/test_inputs.py

raw
1 import pytest
2
3 from allauth.headless.socialaccount.inputs import ProviderTokenInput
4
5
6 @pytest.mark.parametrize("client_id", ["client1", "client2"])
7 def test_provider_token_multiple_apps(settings, db, client_id):
8 gsettings = {
9 "APPS": [
10 {"client_id": "client1", "secret": "secret"},
11 {"client_id": "client2", "secret": "secret"},
12 ]
13 }
14 settings.SOCIALACCOUNT_PROVIDERS = {"google": gsettings}
15
16 inp = ProviderTokenInput(
17 {
18 "provider": "google",
19 "process": "login",
20 "token": {"client_id": client_id, "id_token": "it", "access_token": "at"},
21 }
22 )
23 assert not inp.is_valid()
24 assert inp.cleaned_data["provider"].app.client_id == client_id
25 assert inp.errors == {"token": ["Invalid token."]}
26
27
28 def test_provider_token_client_id_required(settings, db):
29 inp = ProviderTokenInput(
30 {
31 "provider": "google",
32 "process": "login",
33 "token": {"id_token": "it", "access_token": "at"},
34 }
35 )
36 assert not inp.is_valid()
37 assert inp.errors == {"token": ["`client_id` required."]}