Skip to content

Commit

Permalink
test(all): remove previous fakeauth instance from tests build_image
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Apr 3, 2024
1 parent e1cb576 commit 965e682
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gateway/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Settings(BaseModel):
# Service URLs
RESULTS_SERVICE_URL: str = os.getenv("RESULTS_SERVICE_URL", "http://localhost:8000")
KONG_ADMIN_SERVICE_URL: str = os.getenv("RESULTS_SERVICE_URL", "http://localhost:8001")
PODORC_SERVICE_URL: str = os.getenv("PODORC_SERVICE_URL", "http://localhost:8002")
PODORC_SERVICE_URL: str = os.getenv("PODORC_SERVICE_URL", "http://localhost:18080")

# UI ID and secret
API_CLIENT_ID: str = os.getenv("API_CLIENT_ID", "api-client")
Expand Down
3 changes: 0 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
from tests.pseudo_auth import BearerAuth


# from tests.pseudo_auth import fakeauth


@pytest.fixture(scope="session")
def test_client():
"""Test API client."""
Expand Down
27 changes: 13 additions & 14 deletions tests/test_kong.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
from starlette import status

from tests.constants import TEST_DS, TEST_PROJECT
from tests.pseudo_auth import fakeauth


class TestKong:
"""Kong EP tests. Dependent on having a running instance of Kong and admin URL defined in ENV."""

def test_list_data_stores(self, test_client, setup_kong):
def test_list_data_stores(self, test_client, setup_kong, test_token):
"""Test the list_data_stores method."""
r = test_client.get("/datastore", auth=fakeauth)
r = test_client.get("/datastore", auth=test_token)
assert r.status_code == status.HTTP_200_OK

json_data = r.json()
Expand All @@ -23,9 +22,9 @@ def test_list_data_stores(self, test_client, setup_kong):
data_store_names = [ds["name"] for ds in data]
assert TEST_DS in data_store_names

def test_list_data_stores_by_project(self, test_client, setup_kong):
def test_list_data_stores_by_project(self, test_client, setup_kong, test_token):
"""Test the list_data_stores_by_project method."""
r = test_client.get(f"/datastore/{TEST_PROJECT}", auth=fakeauth)
r = test_client.get(f"/datastore/{TEST_PROJECT}", auth=test_token)
assert r.status_code == status.HTTP_200_OK

json_data = r.json()
Expand All @@ -39,7 +38,7 @@ def test_list_data_stores_by_project(self, test_client, setup_kong):
assert data_store["name"] == TEST_PROJECT
assert data_store["methods"] == ["GET", "POST", "PUT", "DELETE"]

def test_create_delete_data_store(self, test_client, setup_kong):
def test_create_delete_data_store(self, test_client, setup_kong, test_token):
"""Test the create_data_store and delete_data_store methods."""
test_ds_name = "theWWW"
new_ds = {
Expand All @@ -49,17 +48,17 @@ def test_create_delete_data_store(self, test_client, setup_kong):
"host": "earth",
"path": "/cloud",
}
r = test_client.post("/datastore", auth=fakeauth, json=new_ds)
r = test_client.post("/datastore", auth=test_token, json=new_ds)
assert r.status_code == status.HTTP_201_CREATED

new_service = r.json()
for k, v in new_ds.items():
assert new_service[k] == v

d = test_client.delete(f"/datastore/{test_ds_name}", auth=fakeauth)
d = test_client.delete(f"/datastore/{test_ds_name}", auth=test_token)
assert d.status_code == status.HTTP_200_OK

def test_connect_disconnect_project_to_datastore(self, test_client, setup_kong):
def test_connect_disconnect_project_to_datastore(self, test_client, setup_kong, test_token):
"""Test the connect_project_to_datastore and disconnect_project methods."""
test_project_name = "Manhattan"
proj_specs = {
Expand All @@ -76,7 +75,7 @@ def test_connect_disconnect_project_to_datastore(self, test_client, setup_kong):
],
"ds_type": "fhir"
}
r = test_client.post("/datastore/project", auth=fakeauth, json=proj_specs)
r = test_client.post("/datastore/project", auth=test_token, json=proj_specs)
assert r.status_code == status.HTTP_200_OK
link_data = r.json()

Expand All @@ -85,20 +84,20 @@ def test_connect_disconnect_project_to_datastore(self, test_client, setup_kong):
assert all(found_keys)
assert link_data["route"]["name"] == test_project_name

d = test_client.put(f"/disconnect/{test_project_name}", auth=fakeauth)
d = test_client.put(f"/disconnect/{test_project_name}", auth=test_token)
assert d.status_code == status.HTTP_200_OK

removed_routes = d.json()["removed_routes"]
assert len(removed_routes) == 1

def test_connect_delete_analysis_to_project(self, test_client, setup_kong):
def test_connect_delete_analysis_to_project(self, test_client, setup_kong, test_token):
"""Test the connect_analysis_to_project method."""
test_analysis = "datalore"
analysis_request = {
"project_id": TEST_PROJECT,
"analysis_id": test_analysis,
}
r = test_client.post("/project/analysis", auth=fakeauth, json=analysis_request)
r = test_client.post("/project/analysis", auth=test_token, json=analysis_request)
assert r.status_code == status.HTTP_202_ACCEPTED

link_data = r.json()
Expand All @@ -109,5 +108,5 @@ def test_connect_delete_analysis_to_project(self, test_client, setup_kong):
assert link_data["consumer"]["username"] == test_analysis
assert link_data["consumer"]["tags"] == [TEST_PROJECT]

d = test_client.delete(f"/analysis/{test_analysis}", auth=fakeauth)
d = test_client.delete(f"/analysis/{test_analysis}", auth=test_token)
assert d.status_code == status.HTTP_200_OK
21 changes: 10 additions & 11 deletions tests/test_podorc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
from starlette import status

from tests.constants import TEST_ANALYSIS
from tests.pseudo_auth import fakeauth


class TestPodOrc:
"""Pod orchestration tests."""

def test_get_po_status(self, test_client, setup_po):
def test_get_po_status(self, test_client, setup_po, test_token):
"""Test the get_analysis_status method."""
r = test_client.get(f"/po/{TEST_ANALYSIS}/status", auth=fakeauth)
r = test_client.get(f"/po/{TEST_ANALYSIS}/status", auth=test_token)
assert r.status_code == status.HTTP_200_OK

resp = r.json()
Expand All @@ -22,9 +21,9 @@ def test_get_po_status(self, test_client, setup_po):
assert pod_name.startswith(TEST_ANALYSIS)
assert pod_status == "running"

def test_get_po_logs(self, test_client, setup_po):
def test_get_po_logs(self, test_client, setup_po, test_token):
"""Test the get_analysis_logs method."""
r = test_client.get(f"/po/{TEST_ANALYSIS}/logs", auth=fakeauth)
r = test_client.get(f"/po/{TEST_ANALYSIS}/logs", auth=test_token)
assert r.status_code == status.HTTP_200_OK

resp = r.json()
Expand All @@ -34,9 +33,9 @@ def test_get_po_logs(self, test_client, setup_po):
assert pod_name.startswith(TEST_ANALYSIS)
assert isinstance(pod_log, list)

def test_get_po_pods(self, test_client, setup_po):
def test_get_po_pods(self, test_client, setup_po, test_token):
"""Test the get_analysis_pods method."""
r = test_client.get(f"/po/{TEST_ANALYSIS}/pods", auth=fakeauth)
r = test_client.get(f"/po/{TEST_ANALYSIS}/pods", auth=test_token)
assert r.status_code == status.HTTP_200_OK

resp = r.json()
Expand All @@ -45,7 +44,7 @@ def test_get_po_pods(self, test_client, setup_po):
assert isinstance(pods, list)
assert len(pods) == 1

def test_create_stop_delete_pod(self, test_client):
def test_create_stop_delete_pod(self, test_client, test_token):
"""Test the create_analysis, stop_analysis, and delete_analysis methods."""
analysis_test = "podorcanalysistest" # Must be all lower case for podorc unittests
test_deploy = {
Expand All @@ -54,7 +53,7 @@ def test_create_stop_delete_pod(self, test_client):
}

# Create pod
create_r = test_client.post("/po", auth=fakeauth, json=test_deploy)
create_r = test_client.post("/po", auth=test_token, json=test_deploy)
assert create_r.status_code == status.HTTP_200_OK

pod_creation_status = create_r.json()
Expand All @@ -63,7 +62,7 @@ def test_create_stop_delete_pod(self, test_client):
time.sleep(2)

# Stop pod
stop_r = test_client.put(f"/po/{analysis_test}/stop", auth=fakeauth)
stop_r = test_client.put(f"/po/{analysis_test}/stop", auth=test_token)
assert stop_r.status_code == status.HTTP_200_OK

pod_stop_resp = stop_r.json()
Expand All @@ -76,7 +75,7 @@ def test_create_stop_delete_pod(self, test_client):
time.sleep(2)

# Delete pod
delete_r = test_client.delete(f"/po/{analysis_test}/delete", auth=fakeauth)
delete_r = test_client.delete(f"/po/{analysis_test}/delete", auth=test_token)
assert delete_r.status_code == status.HTTP_200_OK

pod_delete_resp = delete_r.json()
Expand Down

0 comments on commit 965e682

Please sign in to comment.