-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional param to the BaseService class to allow for passing ot…
…her licenses to FastAPI (#526) * added optional parameter to the BaseService class to accept either the DIBBs default Creative Commons Zero v1.0 or the MIT license from a new LicenseType class * added a test to pass a both the DIBBs default and MIT licenses to the BaseService
- Loading branch information
1 parent
4fd35ac
commit 6632a53
Showing
2 changed files
with
52 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,43 @@ | ||
from phdi.containers.base_service import BaseService | ||
from phdi.containers.base_service import LicenseType, BaseService | ||
from fastapi.testclient import TestClient | ||
from pathlib import Path | ||
from importlib import metadata | ||
|
||
default_app_version = metadata.version("phdi") | ||
default_app_contact = BaseService.DIBBS_CONTACT | ||
default_app_license = LicenseType.CreativeCommonsZero | ||
alternate_app_license = LicenseType.MIT | ||
|
||
|
||
def test_base_service(): | ||
service = BaseService( | ||
"test_service", Path(__file__).parent.parent / "assets" / "test_description.md" | ||
service_name="test_service", | ||
description_path=Path(__file__).parent.parent | ||
/ "assets" | ||
/ "test_description.md", | ||
) | ||
assert service.app.title == "test_service" | ||
assert service.app.version == metadata.version("phdi") | ||
assert service.app.contact == { | ||
"name": "CDC Public Health Data Infrastructure", | ||
"url": "https://cdcgov.github.io/phdi-site/", | ||
"email": "dmibuildingblocks@cdc.gov", | ||
} | ||
assert service.app.license_info == { | ||
"name": "Creative Commons Zero v1.0 Universal", | ||
"url": "https://creativecommons.org/publicdomain/zero/1.0/", | ||
} | ||
assert service.app.version == default_app_version | ||
assert service.app.contact == default_app_contact | ||
assert service.app.license_info == default_app_license | ||
assert service.app.description == "This is a test description." | ||
|
||
client = TestClient(service.start()) | ||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert response.json() == {"status": "OK"} | ||
|
||
|
||
def test_base_service_alternate_license(): | ||
service = BaseService( | ||
service_name="test_service", | ||
description_path=Path(__file__).parent.parent | ||
/ "assets" | ||
/ "test_description.md", | ||
license_info=alternate_app_license, | ||
) | ||
assert service.app.title == "test_service" | ||
assert service.app.version == default_app_version | ||
assert service.app.contact == default_app_contact | ||
assert service.app.license_info == alternate_app_license | ||
assert service.app.description == "This is a test description." |