Skip to content

Commit

Permalink
Merge branch 'main' into dunitz/cache-invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
MDunitz authored Sep 30, 2021
2 parents 4ba5a25 + 8e0dd91 commit db5f22d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
RequestException,
DatasetNotFoundError,
TombstoneError,
DatasetMetadataError
DatasetMetadataError,
)
from server.common.health import health_check
from server.common.utils.utils import path_join, Float32JSONEncoder
Expand Down
5 changes: 4 additions & 1 deletion server/common/config/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def get_client_config(app_config, data_adaptor, current_app):
library_versions["cellxgene"] = cellxgene_display_version

# links
links = {"about-dataset": about}
links = {
"collections-home-page": server_config.get_web_base_url(),
"about-dataset": about,
}

# parameters
parameters = {
Expand Down
1 change: 1 addition & 0 deletions server/data_common/dataset_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def get_dataset_and_collection_metadata(dataset_explorer_location: str, app_conf

metadata = {
"dataset_name": [dataset["name"] for dataset in res["datasets"] if dataset["id"] == dataset_id][0],
"dataset_id": dataset_id,
"collection_url": f"{web_base_url}/collections/{collection_id}{suffix}",
"collection_name": res["name"],
"collection_description": res["description"],
Expand Down
39 changes: 38 additions & 1 deletion server/tests/unit/common/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,6 @@ def test_metadata_cache_item_invalidated_on_errors(self, mock_dp, mock_expire):
self.assertEqual(good_response.status_code, 200)
self.assertEqual(mock_dp.call_count, 2)


class TestDatasetMetadata(BaseTest):
@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -834,6 +833,7 @@ def test_dataset_metadata_api_called(self, mock_get, mock_dp):
self.assertEqual(response_obj["dataset_name"], "Test Dataset")

expected_url = f"https://cellxgene.staging.single-cell.czi.technology/collections/{response_body['id']}"
self.assertEqual(response_obj["dataset_id"], response_body["datasets"][0]["id"])
self.assertEqual(response_obj["collection_url"], expected_url)
self.assertEqual(response_obj["collection_name"], response_body["name"])
self.assertEqual(response_obj["collection_contact_email"], response_body["contact_email"])
Expand Down Expand Up @@ -872,6 +872,43 @@ def test_dataset_metadata_api_fails_gracefully_on_connection_failure(self, mock_

self.assertEqual(result.status_code, HTTPStatus.BAD_REQUEST)

class TestConfigEndpoint(BaseTest):

@classmethod
def setUpClass(cls):
cls.data_locator_api_base = "api.cellxgene.staging.single-cell.czi.technology/dp/v1"
cls.app__web_base_url = "https://cellxgene.staging.single-cell.czi.technology/"
cls.config = AppConfig()
cls.config.update_server_config(
data_locator__api_base=cls.data_locator_api_base,
app__web_base_url=cls.app__web_base_url,
multi_dataset__dataroot={"e": {"base_url": "e", "dataroot": FIXTURES_ROOT}},
app__flask_secret_key="testing",
app__debug=True,
data_locator__s3__region_name="us-east-1",
)
super().setUpClass(cls.config)

cls.app.testing = True
cls.client = cls.app.test_client()


def test_config_has_collections_home_page(self):
self.TEST_DATASET_URL_BASE = "/e/pbmc3k_v0.cxg"
self.TEST_URL_BASE = f"{self.TEST_DATASET_URL_BASE}/api/v0.2/"

endpoint = "config"
url = f"{self.TEST_URL_BASE}{endpoint}"
# print(f"SDFSDF SDJFSF D {url}")
result = self.client.get(url)
self.assertEqual(result.status_code, HTTPStatus.OK)
self.assertEqual(result.headers["Content-Type"], "application/json")
result_data = json.loads(result.data)
self.assertEqual(
result_data["config"]["links"]["collections-home-page"],
self.app__web_base_url[:-1]
)


class MockResponse:
def __init__(self, body, status_code):
Expand Down

0 comments on commit db5f22d

Please sign in to comment.