Skip to content

Commit ab50d06

Browse files
authored
test: Add new tests for Oauth and Login Client (#403)
* add tests for oauth and login client * remove duplicate lines
1 parent a931a60 commit ab50d06

File tree

2 files changed

+103
-17
lines changed

2 files changed

+103
-17
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import pytest
2+
3+
from linode_api4 import OAuthScopes
4+
from linode_api4.login_client import LinodeLoginClient
5+
from linode_api4.objects import OAuthClient
6+
7+
8+
@pytest.fixture
9+
def linode_login_client(test_oauth_client):
10+
client_id = test_oauth_client.id
11+
client_secret = test_oauth_client.secret
12+
13+
login_client = LinodeLoginClient(client_id, client_secret)
14+
15+
yield login_client
16+
17+
18+
@pytest.fixture
19+
def test_oauth_client_two(test_linode_client):
20+
client = test_linode_client
21+
oauth_client = client.account.oauth_client_create(
22+
"test-oauth-client-two", "https://localhost/oauth/callback"
23+
)
24+
25+
yield oauth_client
26+
27+
oauth_client.delete()
28+
29+
30+
def test_get_oathclient(test_linode_client, test_oauth_client):
31+
client = test_linode_client
32+
33+
oauth_client = client.load(OAuthClient, test_oauth_client.id)
34+
35+
assert "test-oauth-client" == oauth_client.label
36+
assert "https://localhost/oauth/callback" == oauth_client.redirect_uri
37+
38+
39+
def test_get_oauth_clients(
40+
test_linode_client, test_oauth_client, test_oauth_client_two
41+
):
42+
oauth_clients = test_linode_client.account.oauth_clients()
43+
44+
id_list = [o_cli.id for o_cli in oauth_clients]
45+
46+
assert str(test_oauth_client.id) in id_list
47+
assert str(test_oauth_client_two.id) in id_list
48+
49+
50+
def test_get_oauth_clients_dont_reveal_secret(test_linode_client):
51+
oauth_client_secret = test_linode_client.account.oauth_clients()[0].secret
52+
53+
assert oauth_client_secret == "<REDACTED>"
54+
55+
56+
def test_edit_oauth_client_details(test_linode_client, test_oauth_client_two):
57+
test_oauth_client_two.redirect_uri = (
58+
"https://localhost/oauth/callback_changed"
59+
)
60+
test_oauth_client_two.label = "new_oauthclient_label"
61+
test_oauth_client_two.save()
62+
63+
oau_client = test_linode_client.load(OAuthClient, test_oauth_client_two.id)
64+
65+
assert oau_client.redirect_uri == "https://localhost/oauth/callback_changed"
66+
assert oau_client.label == "new_oauthclient_label"
67+
68+
69+
def test_oauth_client_reset_secrets(test_oauth_client_two):
70+
old_secret = test_oauth_client_two.secret
71+
72+
new_secret = test_oauth_client_two.reset_secret()
73+
74+
assert old_secret != new_secret
75+
76+
77+
def test_linode_login_client_generate_default_login_url(linode_login_client):
78+
client_id = linode_login_client.client_id
79+
url = linode_login_client.generate_login_url()
80+
81+
assert (
82+
"https://login.linode.com/oauth/authorize?client_id="
83+
+ str(client_id)
84+
+ "&response_type=code"
85+
== url
86+
)
87+
88+
89+
def test_linode_login_client_generate_login_url_with_scope(linode_login_client):
90+
url = linode_login_client.generate_login_url(
91+
scopes=OAuthScopes.Linodes.read_write
92+
)
93+
94+
assert "scopes=linodes%3Aread_write" in url
95+
96+
97+
def test_linode_login_client_expire_token(
98+
linode_login_client, test_oauth_client
99+
):
100+
result = linode_login_client.expire_token(token=test_oauth_client.secret)
101+
102+
assert result is True

test/integration/models/account/test_account.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33

44
import pytest
55

6-
from linode_api4.objects import (
7-
Account,
8-
AccountSettings,
9-
Event,
10-
Login,
11-
OAuthClient,
12-
User,
13-
)
6+
from linode_api4.objects import Account, AccountSettings, Event, Login, User
147

158

169
@pytest.mark.smoke
@@ -80,15 +73,6 @@ def test_latest_get_event(test_linode_client):
8073
assert label in latest_event["entity"]["label"]
8174

8275

83-
def test_get_oathclient(test_linode_client, test_oauth_client):
84-
client = test_linode_client
85-
86-
oauth_client = client.load(OAuthClient, test_oauth_client.id)
87-
88-
assert "test-oauth-client" == oauth_client.label
89-
assert "https://localhost/oauth/callback" == oauth_client.redirect_uri
90-
91-
9276
def test_get_user(test_linode_client):
9377
client = test_linode_client
9478

0 commit comments

Comments
 (0)