Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrdnbradford committed Sep 26, 2024
1 parent 96723da commit 2d91638
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions oauthenticator/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import re
from unittest import mock
from unittest.mock import AsyncMock

from pytest import fixture, mark, raises
from traitlets.config import Config
Expand Down Expand Up @@ -380,3 +381,33 @@ async def test_deprecated_config(

expected_log_tuple = (test_logger.name, expect_loglevel, expect_message)
assert expected_log_tuple in captured_log_tuples


@mark.asyncio
async def test_nested_group_memberships():
mock_fetch_member_groups = AsyncMock(
return_value={'group1', 'nested_group1', 'nested_group2'}
)

authenticator = GoogleOAuthenticator()
authenticator._fetch_member_groups = mock_fetch_member_groups

user_info = {'name': 'testuser', 'email': '[email protected]'}

result = await authenticator._fetch_member_groups(user_info['email'], 'example.com')
assert 'nested_group1' in result
assert 'nested_group2' in result


@mark.asyncio
async def test_user_not_in_nested_group():
mock_fetch_member_groups = AsyncMock(return_value={'group1', 'group2'})

authenticator = GoogleOAuthenticator()
authenticator._fetch_member_groups = mock_fetch_member_groups

user_info = {'name': 'testuser', 'email': '[email protected]'}

result = await authenticator._fetch_member_groups(user_info['email'], 'example.com')
assert 'nested_group1' not in result
assert 'nested_group2' not in result

0 comments on commit 2d91638

Please sign in to comment.