Skip to content

Commit 00b17df

Browse files
authored
Cleanup Smartsheet (#2)
* ci: git workflows, openapirc_async, removes 404 * openapi_examples * fixes typo in tag and publish workflow * updates readme
1 parent 31cf598 commit 00b17df

6 files changed

Lines changed: 91 additions & 70 deletions

File tree

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ jobs:
121121
- name: Update version
122122
run: |
123123
sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc.json
124+
sed -i --debug --expression="s|packageVersion.*|packageVersion\": \"${{ needs.bump_version.outputs.new_version }}\"|" openapirc_async.json
124125
- name: Set up Python 3.10
125126
uses: actions/setup-python@v5
126127
with:
@@ -148,12 +149,28 @@ jobs:
148149
rm -f aind-smartsheet-service-client/.gitlab-ci.yml
149150
rm -f aind-smartsheet-service-client/git_push.sh
150151
rm -f aind-smartsheet-service-client/.travis.yml
152+
- name: Generate Python Async Client
153+
uses: openapi-generators/openapitools-generator-action@v1.5.0
154+
with:
155+
generator: python
156+
generator-tag: v7.13.0
157+
openapi-file: openapi.json
158+
config-file: openapirc_async.json
159+
- name: Handle async files
160+
run: |
161+
rm -rf aind-smartsheet-service-async-client
162+
mv python-client aind-smartsheet-service-async-client
163+
rm -rf aind-smartsheet-service-async-client/.github
164+
rm -f aind-smartsheet-service-async-client/.gitignore
165+
rm -f aind-smartsheet-service-async-client/.gitlab-ci.yml
166+
rm -f aind-smartsheet-service-async-client/git_push.sh
167+
rm -f aind-smartsheet-service-async-client/.travis.yml
151168
- name: Commit changes
152169
uses: EndBug/add-and-commit@v9
153170
with:
154171
default_author: github_actions
155-
message: "ci: add client [skip actions]"
156-
add: '["openapirc.json","aind-smartsheet-service-client"]'
172+
message: "ci: add clients [skip actions]"
173+
add: '["openapirc.json","aind-smartsheet-service-client","openapirc_async.json","aind-smartsheet-service-async-client"]'
157174
update_tag:
158175
runs-on: ubuntu-latest
159176
needs: [bump_version, build_client]
@@ -217,3 +234,27 @@ jobs:
217234
with:
218235
packages-dir: ./aind-smartsheet-service-client/dist
219236
password: ${{ secrets.AIND_PYPI_TOKEN }}
237+
publish_async_client:
238+
runs-on: ubuntu-latest
239+
needs: update_tag
240+
defaults:
241+
run:
242+
working-directory: ./aind-smartsheet-service-async-client
243+
steps:
244+
- uses: actions/checkout@v4
245+
- name: Pull latest changes
246+
run: git pull origin main
247+
- name: Set up Python 3.10
248+
uses: actions/setup-python@v5
249+
with:
250+
python-version: '3.10'
251+
- name: Install dependencies
252+
run: |
253+
pip install --upgrade setuptools wheel twine build
254+
python -m build
255+
twine check dist/*
256+
- name: Publish on PyPI
257+
uses: pypa/gh-action-pypi-publish@release/v1.12
258+
with:
259+
packages-dir: ./aind-smartsheet-service-async-client/dist
260+
password: ${{ secrets.AIND_PYPI_TOKEN }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ REST service to connect to Smartsheet and return information.
1515
- The client code is autogenerated using an openapi generator.
1616
- On a push to main, a python library will be built and published to PyPI.
1717
- The client can then be pip installed as `pip install aind-smartsheet-service-client`
18+
- An async client can be pip installed as `pip install aind-smartsheet-service-async-client`

aind-smartsheet-service-server/src/aind_smartsheet_service_server/route.py

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import List, Optional
44

5-
from fastapi import APIRouter, Depends, HTTPException, Query, status
5+
from fastapi import APIRouter, Depends, Query, status
66

77
from aind_smartsheet_service_server.handler import SessionHandler
88
from aind_smartsheet_service_server.models import (
@@ -41,14 +41,27 @@ async def get_health() -> HealthCheck:
4141
"/funding",
4242
response_model=List[FundingModel],
4343
)
44-
async def get_funding(
44+
def get_funding(
4545
project_name: Optional[str] = Query(
4646
default=None,
47-
examples=["Discovery-Neuromodulator circuit dynamics during foraging"],
47+
openapi_examples={
48+
"default": {
49+
"summary": "A sample project name",
50+
"description": "Example project name for smartsheet",
51+
"value": "Discovery-Neuromodulator circuit dynamics"
52+
" during foraging",
53+
}
54+
},
4855
),
4956
subproject: Optional[str] = Query(
5057
default=None,
51-
examples=["Subproject 2 Molecular Anatomy Cell Types"],
58+
openapi_examples={
59+
"default": {
60+
"summary": "A sample subproject",
61+
"description": "Example subproject name",
62+
"value": "Subproject 2 Molecular Anatomy Cell Types",
63+
}
64+
},
5265
),
5366
session: SmartsheetClient = Depends(get_session),
5467
):
@@ -65,17 +78,14 @@ async def get_funding(
6578
content = SessionHandler(session=session).get_project_funding_info(
6679
sheet_model=sheet, project_name=project_name, subproject=subproject
6780
)
68-
if len(content) == 0:
69-
raise HTTPException(status_code=404, detail="Not found")
70-
else:
71-
return content
81+
return content
7282

7383

7484
@router.get(
7585
"/project_names",
7686
response_model=List[str],
7787
)
78-
async def get_project_names(
88+
def get_project_names(
7989
session: SmartsheetClient = Depends(get_session),
8090
):
8191
"""
@@ -91,25 +101,26 @@ async def get_project_names(
91101
content = SessionHandler(session=session).get_project_names(
92102
sheet_model=sheet
93103
)
94-
if len(content) == 0:
95-
raise HTTPException(status_code=404, detail="Not found")
96-
else:
97-
return content
104+
return content
98105

99106

100107
@router.get(
101108
"/protocols",
102109
response_model=List[ProtocolsModel],
103110
)
104-
async def get_protocols(
111+
def get_protocols(
105112
protocol_name: Optional[str] = Query(
106113
default=None,
107-
examples=[
108-
(
109-
"Tetrahydrofuran and Dichloromethane Delipidation of a Whole "
110-
"Mouse Brain"
111-
)
112-
],
114+
openapi_examples={
115+
"default": {
116+
"summary": "A sample protocol name",
117+
"description": "Example protocol name",
118+
"value": (
119+
"Tetrahydrofuran and Dichloromethane Delipidation of a "
120+
"Whole Mouse Brain"
121+
),
122+
}
123+
},
113124
),
114125
session: SmartsheetClient = Depends(get_session),
115126
):
@@ -126,20 +137,23 @@ async def get_protocols(
126137
content = SessionHandler(session=session).get_protocols_info(
127138
sheet_model=sheet, protocol_name=protocol_name
128139
)
129-
if len(content) == 0:
130-
raise HTTPException(status_code=404, detail="Not found")
131-
else:
132-
return content
140+
return content
133141

134142

135143
@router.get(
136144
"/perfusions",
137145
response_model=List[PerfusionsModel],
138146
)
139-
async def get_perfusions(
147+
def get_perfusions(
140148
subject_id: Optional[str] = Query(
141149
default=None,
142-
examples=["689418"],
150+
openapi_examples={
151+
"default": {
152+
"summary": "A sample subject id",
153+
"description": "Example subject id",
154+
"value": "689418",
155+
}
156+
},
143157
),
144158
session: SmartsheetClient = Depends(get_session),
145159
):
@@ -156,7 +170,4 @@ async def get_perfusions(
156170
content = SessionHandler(session=session).get_perfusions_info(
157171
sheet_model=sheet, subject_id=subject_id
158172
)
159-
if len(content) == 0:
160-
raise HTTPException(status_code=404, detail="Not found")
161-
else:
162-
return content
173+
return content

aind-smartsheet-service-server/tests/test_route.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Test routes"""
22

3-
from unittest.mock import MagicMock, patch
3+
from unittest.mock import MagicMock
44

55
import pytest
66
from starlette.testclient import TestClient
@@ -55,14 +55,6 @@ def test_get_200_funding(
5555
assert 200 == response.status_code
5656
assert expected_response == response.json()
5757

58-
def test_get_404_funding(
59-
self, client: TestClient, mock_get_raw_funding_sheet: MagicMock
60-
):
61-
"""Tests a response when fetching funding info for missing project"""
62-
63-
response = client.get("/funding?project_name=MISSING")
64-
assert 404 == response.status_code
65-
6658
def test_get_200_project_names(
6759
self, client: TestClient, mock_get_raw_funding_sheet: MagicMock
6860
):
@@ -91,19 +83,6 @@ def test_get_200_project_names(
9183
assert 200 == response.status_code
9284
assert expected_response == response.json()
9385

94-
def test_get_404_project_names(
95-
self, client: TestClient, mock_get_raw_funding_sheet: MagicMock
96-
):
97-
"""Tests an empty response when fetching project_names"""
98-
99-
with patch(
100-
"aind_smartsheet_service_server.handler.SessionHandler"
101-
".get_parsed_sheet",
102-
return_value=[],
103-
):
104-
response = client.get("/project_names")
105-
assert 404 == response.status_code
106-
10786
def test_get_200_protocols(
10887
self, client: TestClient, mock_get_raw_protocols_sheet: MagicMock
10988
):
@@ -127,14 +106,6 @@ def test_get_200_protocols(
127106
assert 200 == response.status_code
128107
assert expected_response == response.json()
129108

130-
def test_get_404_protocols(
131-
self, client: TestClient, mock_get_raw_protocols_sheet: MagicMock
132-
):
133-
"""Tests a response when fetching protocol info for missing name"""
134-
135-
response = client.get("/protocols?protocol_name=MISSING")
136-
assert 404 == response.status_code
137-
138109
def test_get_200_perfusions(
139110
self, client: TestClient, mock_get_raw_perfusions_sheet: MagicMock
140111
):
@@ -159,14 +130,6 @@ def test_get_200_perfusions(
159130
assert 200 == response.status_code
160131
assert expected_response == response.json()
161132

162-
def test_get_404_perfusions(
163-
self, client: TestClient, mock_get_raw_perfusions_sheet: MagicMock
164-
):
165-
"""Tests a response when fetching perfusions for missing subject"""
166-
167-
response = client.get("/perfusions?subject_id=000")
168-
assert 404 == response.status_code
169-
170133

171134
if __name__ == "__main__":
172135
pytest.main([__file__])

openapirc_async.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageName": "aind_smartsheet_service_async_client",
3+
"projectName": "aind-smartsheet-service-async-client",
4+
"packageVersion": "0.0.0"
5+
}

0 commit comments

Comments
 (0)