-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
# noinspection PyPackageRequirements | ||
import pytest | ||
|
||
from krs.token import get_token | ||
from krs import users | ||
|
||
from ..util import keycloak_bootstrap | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_list_users_empty(keycloak_bootstrap): | ||
ret = await users.list_users(rest_client=keycloak_bootstrap) | ||
assert ret == {} | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_list_users(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
|
@@ -64,6 +67,7 @@ async def test_list_user_attr_query_invalid(keycloak_bootstrap): | |
assert not await users.list_users(attr_query={f"{char}": "not_impl_name"}, rest_client=keycloak_bootstrap) | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_user_info(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
|
@@ -72,6 +76,8 @@ async def test_user_info(keycloak_bootstrap): | |
assert ret['lastName'] == 'last' | ||
assert ret['email'] == 'foo@test' | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_create_user(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='Fĭrst', last_name='Mü Lăst', email='foo@test', rest_client=keycloak_bootstrap) | ||
|
@@ -100,6 +106,9 @@ async def test_modify_user(keycloak_bootstrap): | |
assert 'foo' in ret['attributes'] | ||
assert ret['attributes']['foo'] == 'bar' | ||
|
||
|
||
# noinspection LongLine | ||
# noinspection PyTypeChecker | ||
@pytest.mark.asyncio | ||
async def test_modify_user_asserts(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
|
@@ -112,59 +121,80 @@ async def test_modify_user_asserts(keycloak_bootstrap): | |
with pytest.raises(RuntimeError): | ||
await users.modify_user('testuser', email={'foo': 'bar'}, rest_client=keycloak_bootstrap) | ||
|
||
|
||
# noinspection LongLine | ||
# noinspection PyPep8Naming | ||
@pytest.mark.asyncio | ||
async def test_modify_user_firstName(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', first_name='bar', rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['firstName'] == 'bar' | ||
|
||
|
||
# noinspection LongLine | ||
# noinspection PyPep8Naming | ||
@pytest.mark.asyncio | ||
async def test_modify_user_lastName(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', last_name='bar', rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['lastName'] == 'bar' | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_modify_user_email(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', email='bar@test', rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['email'] == 'bar@test' | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_modify_user_existing_attr(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', attribs={'foo': 'bar'}, rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', attribs={'baz': 'foo'}, rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['attributes'] == {'foo': 'bar', 'baz': 'foo', 'canonical_email': '[email protected]'} | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_modify_user_attr_list(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', attribs={'foo': ['bar', 'baz']}, rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', attribs={'baz': [1, 2, 3]}, rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['attributes'] == {'foo': ['bar', 'baz'], 'baz': ['1', '2', '3'], 'canonical_email': '[email protected]'} | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_modify_user_del_attr(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', attribs={'foo': 'bar'}, rest_client=keycloak_bootstrap) | ||
await users.modify_user('testuser', attribs={'foo': None, 'baz': 'foo'}, rest_client=keycloak_bootstrap) | ||
ret = await users.user_info('testuser', rest_client=keycloak_bootstrap) | ||
assert ret['attributes'] == {'baz': 'foo', 'canonical_email': '[email protected]'} | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_set_user_password(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
await users.set_user_password('testuser', 'foo', rest_client=keycloak_bootstrap) | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_set_user_password_bad(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
with pytest.raises(Exception): | ||
# noinspection PyTypeChecker | ||
await users.set_user_password('testuser', ['f', 'o', 'o'], rest_client=keycloak_bootstrap) | ||
|
||
|
||
# noinspection LongLine | ||
@pytest.mark.asyncio | ||
async def test_delete_user(keycloak_bootstrap): | ||
await users.create_user('testuser', first_name='first', last_name='last', email='foo@test', rest_client=keycloak_bootstrap) | ||
|