2022-03-04 18:51:33 +01:00
|
|
|
import email
|
2022-03-06 15:29:00 +01:00
|
|
|
import logging
|
|
|
|
from .api import Authentik
|
2022-03-06 12:31:12 +01:00
|
|
|
from .models import User
|
|
|
|
import pytest
|
2022-03-04 18:51:33 +01:00
|
|
|
|
|
|
|
|
2022-03-06 12:31:12 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def api() -> Authentik:
|
2022-04-22 18:34:48 +02:00
|
|
|
try:
|
|
|
|
return Authentik(base="http://localhost:9000/", token="foobar123", )
|
|
|
|
except:
|
|
|
|
pytest.skip("API not reachable? Did you start docker-compose?")
|
2022-03-06 12:31:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_get_user_by_username(api: Authentik):
|
|
|
|
u = User(username="akadmin",
|
|
|
|
name="",
|
|
|
|
groups=[],
|
|
|
|
email="",
|
|
|
|
is_active=True,
|
|
|
|
attributes={}
|
|
|
|
)
|
|
|
|
u = api.get_user(u)
|
|
|
|
assert not u == None
|
|
|
|
assert u.username == "akadmin"
|
2022-03-04 18:51:33 +01:00
|
|
|
|
2022-03-06 12:31:12 +01:00
|
|
|
|
|
|
|
def test_create_user(api: Authentik):
|
2022-03-04 18:51:33 +01:00
|
|
|
u = User(username="banane",
|
|
|
|
name="banane",
|
|
|
|
groups=[],
|
|
|
|
email="foo@example.org",
|
|
|
|
is_active=True,
|
|
|
|
attributes={}
|
2022-03-06 12:31:12 +01:00
|
|
|
)
|
|
|
|
if(api.get_user(u)):
|
|
|
|
api.delete_user(api.get_user(u))
|
|
|
|
|
|
|
|
assert api.get_user(u) == None
|
|
|
|
|
|
|
|
c = api.create_user(u)
|
2022-03-04 18:51:33 +01:00
|
|
|
assert u.username == c.username
|
|
|
|
assert not c.pk == None
|