Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
This is just minor stylistic changes.
  • Loading branch information
gravesm committed Oct 15, 2024
1 parent e33d9ea commit c47e8f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion awxkit/awxkit/api/pages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def get_oauth2_token(self, username='', password='', client_id=None, description
try:
return self._request_token(urls, username, password, client_id, description, client_secret, scope)
except exc.NotFound:
urls: AuthUrls = {
urls = {

Check warning on line 192 in awxkit/awxkit/api/pages/base.py

View check run for this annotation

Codecov / codecov/patch

awxkit/awxkit/api/pages/base.py#L188-L192

Added lines #L188 - L192 were not covered by tests
"access_token": f"{config.api_base_path}o/token/",
"personal_token": f"{config.api_base_path}v2/users/{username}/personal_tokens/",
}
Expand Down
28 changes: 14 additions & 14 deletions awxkit/test/api/pages/test_base.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from unittest.mock import Mock, PropertyMock

from http.client import NOT_FOUND
import pytest
from pytest_mock import MockerFixture
from requests import Response

from awxkit.api.pages import Base
from awxkit.config import config


@pytest.fixture(autouse=True)
def setup_config():
config.credentials = {"default": {"username": "foo", "password": "bar"}}
config.base_url = ""
def setup_config(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(config, "credentials", {"default": {"username": "foo", "password": "bar"}}, raising=False)
monkeypatch.setattr(config, "base_url", "", raising=False)


@pytest.fixture
def response():
r = Mock()
def response(mocker):
r = mocker.Mock()
r.status_code = NOT_FOUND
r.json.return_value = {
"token": "my_personal_token",
Expand All @@ -25,35 +25,35 @@ def response():


@pytest.mark.parametrize(
"kwargs,url,token",
("auth_creds", "url", "token"),
[
({"client_id": "foo", "client_secret": "bar"}, "/o/token/", "my_token"),
({"client_id": "foo"}, "/o/token/", "my_token"),
({}, "/api/gateway/v1/tokens/", "my_personal_token"),
],
)
def test_get_oauth2_token_from_gateway(mocker, response, kwargs, url, token):
def test_get_oauth2_token_from_gateway(mocker: MockerFixture, response: Response, auth_creds, url, token):
post = mocker.patch("requests.Session.post", return_value=response)
base = Base()
ret = base.get_oauth2_token(**kwargs)
ret = base.get_oauth2_token(**auth_creds)
assert post.call_count == 1
assert post.call_args.args[0] == url
assert ret == token


@pytest.mark.parametrize(
"kwargs,url,token",
("auth_creds", "url", "token"),
[
({"client_id": "foo", "client_secret": "bar"}, "/api/o/token/", "my_token"),
({"client_id": "foo"}, "/api/o/token/", "my_token"),
({}, "/api/v2/users/foo/personal_tokens/", "my_personal_token"),
],
)
def test_get_oauth2_token_from_controller(mocker, response, kwargs, url, token):
type(response).ok = PropertyMock(side_effect=[False, True])
def test_get_oauth2_token_from_controller(mocker: MockerFixture, response: Response, auth_creds, url, token):
type(response).ok = mocker.PropertyMock(side_effect=[False, True])
post = mocker.patch("requests.Session.post", return_value=response)
base = Base()
ret = base.get_oauth2_token(**kwargs)
ret = base.get_oauth2_token(**auth_creds)
assert post.call_count == 2
assert post.call_args.args[0] == url
assert ret == token

0 comments on commit c47e8f8

Please sign in to comment.