Coverage for test_checks.py: 100%

1 from plain.auth import get_user_model

2 from plain.oauth.models import OAuthConnection

3

4

5 def test_oauth_provider_keys_check_pass(db, settings):

6 settings.OAUTH_LOGIN_PROVIDERS = {

7 "google": {

8 "client_id": "test_client_id",

9 "client_secret": "test_client_secret",

10 },

11 "foo": {

12 "client_id": "test_client_id",

13 "client_secret": "test_client_secret",

14 },

15 }

16

17 user = get_user_model().objects.create(

18 username="test_user", email="test@example.com"

19 )

20

21 OAuthConnection.objects.create(

22 user=user,

23 provider_key="google",

24 provider_user_id="test_provider_user_id",

25 access_token="test",

26 )

27

28 errors = OAuthConnection.check(databases=["default"])

29 assert len(errors) == 0

30

31

32 def test_oauth_provider_keys_check_fail(db, settings):

33 settings.OAUTH_LOGIN_PROVIDERS = {

34 "google": {

35 "client_id": "test_client_id",

36 "client_secret": "test_client_secret",

37 },

38 "foo": {

39 "client_id": "test_client_id",

40 "client_secret": "test_client_secret",

41 },

42 }

43

44 user = get_user_model().objects.create(

45 username="test_user", email="test@example.com"

46 )

47

48 OAuthConnection.objects.create(

49 user=user,

50 provider_key="google",

51 provider_user_id="test_provider_user_id",

52 access_token="test",

53 )

54 OAuthConnection.objects.create(

55 user=user,

56 provider_key="bar",

57 provider_user_id="test_provider_user_id",

58 access_token="test",

59 )

60

61 errors = OAuthConnection.check(databases=["default"])

62 assert len(errors) == 1

63 assert (

64 errors[0].msg

65 == "The following OAuth providers are in the database but not in the settings: bar"

66 )