Skip to content

Commit

Permalink
tests: use random_token utility method from pytest-iam
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Mar 12, 2024
1 parent 5031657 commit 4aa69c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
15 changes: 1 addition & 14 deletions web/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import datetime
import threading
import time
import uuid
Expand Down Expand Up @@ -54,22 +53,10 @@ def iam_client(iam_server):

@pytest.fixture
def iam_token(iam_server, iam_client, iam_user):
iam_token = iam_server.models.Token(
access_token="access_token_example",
audience=iam_client,
iam_token = iam_server.random_token(
client=iam_client,
id="token_id",
issue_date=datetime.datetime.now(tz=datetime.timezone.utc),
lifetime=36000,
refresh_token="refresh_token_example",
revokation_date=None,
scope=["openid", "profile", "email"],
subject=iam_user,
token_id="token_id",
type="access_token",
)
iam_token.save()

yield iam_token
iam_token.delete()

Expand Down
38 changes: 4 additions & 34 deletions web/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,11 @@ def test_api_meetings_invalid_token(client_app):


def test_api_meetings_token_expired(client_app, iam_server, iam_client, iam_user, user):
iam_token = iam_server.models.Token(
access_token="access_token_example",
audience=iam_client,
iam_token = iam_server.random_token(
client=iam_client,
id="token_id",
issue_date=datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc),
lifetime=36000,
refresh_token="refresh_token_example",
revokation_date=None,
scope=["openid", "profile", "email"],
subject=iam_user,
token_id="token_id",
type="access_token",
issue_date=datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc),
)
iam_token.save()

client_app.get(
"/api/meetings",
Expand All @@ -57,20 +47,10 @@ def test_api_meetings_client_id_missing_in_token_audience(
client_app, iam_server, iam_client, iam_user, user
):
iam_token = iam_server.models.Token(
access_token="access_token_example",
audience="some-other-audience",
client=iam_client,
id="token_id",
issue_date=datetime.datetime.now(tz=datetime.timezone.utc),
lifetime=36000,
refresh_token="refresh_token_example",
revokation_date=None,
scope=["openid", "profile", "email"],
subject=iam_user,
token_id="token_id",
type="access_token",
audience="some-other-audience",
)
iam_token.save()

client_app.get(
"/api/meetings",
Expand All @@ -85,20 +65,10 @@ def test_api_meetings_missing_scope_in_token(
client_app, iam_server, iam_client, iam_user, user
):
iam_token = iam_server.models.Token(
access_token="access_token_example",
audience=iam_client,
client=iam_client,
id="token_id",
issue_date=datetime.datetime.now(tz=datetime.timezone.utc),
lifetime=36000,
refresh_token="refresh_token_example",
revokation_date=None,
scope=["openid"],
subject=iam_user,
token_id="token_id",
type="access_token",
scope=["openid"],
)
iam_token.save()

client_app.get(
"/api/meetings",
Expand Down

0 comments on commit 4aa69c7

Please sign in to comment.