Skip to content

Commit

Permalink
add unit test for resourceset
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed May 21, 2024
1 parent 91b2faa commit 8148c98
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
25 changes: 25 additions & 0 deletions microservices/gatewayApi/tests/clients/test_uma_resourceset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from clients.uma.resourceset import map_res_name_to_id

def test_map_res_name_to_id(mocker, app):
# Mock the Flask app 'config' and 'logger'
class mock_patch:
config = {
"resourceAuthServer": {
"serverUrl": "http://keycloak",
"realm": "master"
}
}
logger = app.logger
mocker.patch('clients.uma.resourceset.app', mock_patch)

# Mock the response from Keycloak to get a particular resourceset
class mock_resourceset:
status_code = 200
def json():
return [
"ecbae046-e0bc-4e96-a3f5-22efb50fef34"
]
mocker.patch("clients.uma.resourceset.requests.get", return_value=mock_resourceset)

id = map_res_name_to_id(None, "NS_RESOURCE")
assert id == "ecbae046-e0bc-4e96-a3f5-22efb50fef34"
21 changes: 0 additions & 21 deletions microservices/gatewayApi/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,15 @@ def app(mocker):
mock_deck(mocker)
mock_kubeapi(mocker)

#mocker.patch("auth.authz.enforce_authorization", return_value=True)

# def mock_resource_protector():
# raise Exception ("Hhu")

# return True
# mocker.patch("authlib.integrations.flask_oauth2.ResourceProtector", return_value=mock_resource_protector)
# mocker.patch("auth.auth.do_validate", return_value=mock_resource_protector)
#mocker.patch("v2.routes.gateway.uma_enforce", mock_resource_protector)
#mocker.patch("clients.keycloak.admin_api", return_value=mock_kc_admin)


from app import create_app

app = create_app()

yield app


@pytest.fixture
def client(app):
"""A test client for the app."""
return app.test_client()


# @pytest.fixture
# def runner(app):
# """A test runner for the app's Click commands."""
# return app.test_cli_runner()

def mock_auth(mocker):
def mock_decorator(f):
@wraps(f)
Expand Down

0 comments on commit 8148c98

Please sign in to comment.