Skip to content

Commit 7c6f7c5

Browse files
authored
Merge pull request #45 from ks6088ts-labs/feature/issue-40_add-tests-docs
add local tests
2 parents 2ab4eac + 7dbcb8a commit 7c6f7c5

15 files changed

+271
-14
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Git
22
GIT_REVISION ?= $(shell git rev-parse --short HEAD)
33
GIT_TAG ?= $(shell git describe --tags --abbrev=0 --always | sed -e s/v//g)
4+
LOG_LEVEL ?= "INFO"
45

56
.PHONY: help
67
help:
@@ -41,7 +42,7 @@ lint: ## lint
4142

4243
.PHONY: test
4344
test: ## run tests
44-
poetry run pytest
45+
poetry run pytest --log-cli-level=$(LOG_LEVEL)
4546

4647
.PHONY: ci-test
4748
ci-test: install-deps-dev format-check lint test ## run CI tests

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ make docker-run
4545
make ci-test-docker
4646
```
4747

48+
### Run local test
49+
50+
Currently almost all tests won't run on CI because it consumes Azure resources.
51+
To run the tests locally, follow the steps below.
52+
53+
```shell
54+
# Run test if RUN_TEST is defined
55+
export RUN_TEST=1
56+
57+
make test
58+
```
59+
4860
## Deployment instructions
4961

5062
### Docker compose

backend/routers/azure_storage_queue.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ async def create_queue(
4141

4242

4343
@router.delete(
44-
"/queues",
44+
"/queues/{queue_name}",
4545
response_model=azure_storage_queue_schemas.DeleteQueueResponse,
4646
status_code=200,
4747
)
4848
async def delete_queue(
49-
body: azure_storage_queue_schemas.DeleteQueueRequest,
49+
queue_name: str,
5050
):
5151
try:
5252
client.delete_queue(
53-
queue_name=body.queue_name,
53+
queue_name=queue_name,
5454
)
5555
except Exception as e:
5656
logger.error(f"Failed to delete queue: {e}")
5757
raise
5858
return azure_storage_queue_schemas.DeleteQueueResponse(
59-
queue_name=body.queue_name,
59+
queue_name=queue_name,
6060
)
6161

6262

backend/schemas/azure_storage_queue.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ class CreateQueueResponse(BaseModel):
1313
queue_name: str
1414

1515

16-
class DeleteQueueRequest(BaseModel):
17-
queue_name: str
18-
19-
2016
class DeleteQueueResponse(BaseModel):
2117
queue_name: str
2218

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [FastAPI > UploadFile class](https://fastapi.tiangolo.com/reference/uploadfile/)
1717
- [FastAPI > Extending OpenAPI](https://fastapi.tiangolo.com/how-to/extending-openapi/)
1818
- [Get started with Azure Blob Storage and Python](https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-python-get-started?tabs=sas-token)
19+
- [FastAPI で実装した様々なエンドポイントのテストを書く(フォームデータの送信、クッキーの確認、ファイルのアップロード等)](https://qiita.com/kurumaebi65/items/d5cda239ef601f4c36ef#%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%82%92%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%83%80%E3%82%A6%E3%83%B3%E3%83%AD%E3%83%BC%E3%83%89)
1920
- [Quickstart: Azure Queue Storage client library for Python](https://learn.microsoft.com/en-us/azure/storage/queues/storage-quickstart-queues-python?tabs=passwordless%2Croles-azure-portal%2Cenvironment-variable-windows%2Csign-in-azure-cli)
2021
- [Azure Event Grid client library for Python - version 4.19.0](https://learn.microsoft.com/en-us/python/api/overview/azure/eventgrid-readme?view=azure-python)
2122
- [Azure Event Grid Client Library Python Samples](https://learn.microsoft.com/en-us/samples/azure/azure-sdk-for-python/eventgrid-samples/)

tests/__init__.py

Whitespace-only changes.

tests/test_main.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/test_smoke.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from tests.utilities import client
2+
3+
4+
def test_main():
5+
response = client.get("/openapi.json")
6+
assert response.status_code == 200
7+
json_response = response.json()
8+
assert json_response["openapi"] == "3.0.0"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from logging import getLogger
2+
3+
import pytest
4+
5+
from tests.utilities import RUN_TEST, client, image
6+
7+
logger = getLogger(__name__)
8+
9+
10+
@pytest.mark.skipif(RUN_TEST, reason="need to launch the backend server first")
11+
def test_azure_ai_document_intelligence():
12+
path_format = "/azure_ai_document_intelligence/{0}"
13+
response = client.post(
14+
url=path_format.format("analyze_document"),
15+
files={
16+
"file": (
17+
"test.png",
18+
image,
19+
"application/octet-stream",
20+
)
21+
},
22+
)
23+
assert response.status_code == 200
24+
logger.info(f"response: {response.json()}")
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from logging import getLogger
2+
3+
import pytest
4+
5+
from tests.utilities import RUN_TEST, client, image
6+
7+
logger = getLogger(__name__)
8+
9+
10+
@pytest.mark.skipif(RUN_TEST, reason="need to launch the backend server first")
11+
def test_azure_ai_vision_image_analyze():
12+
path_format = "/azure_ai_vision/{0}"
13+
response = client.post(
14+
url=path_format.format("image/analyze"),
15+
files={
16+
"file": (
17+
"test.png",
18+
image,
19+
"application/octet-stream",
20+
)
21+
},
22+
)
23+
assert response.status_code == 200
24+
logger.info(f"response: {response.json()}")
25+
26+
27+
@pytest.mark.skipif(RUN_TEST, reason="need to launch the backend server first")
28+
def test_azure_ai_vision_image_vectorize():
29+
path_format = "/azure_ai_vision/{0}"
30+
response = client.post(
31+
url=path_format.format("image/vectorize"),
32+
files={
33+
"file": (
34+
"test.png",
35+
image,
36+
"application/octet-stream",
37+
)
38+
},
39+
)
40+
assert response.status_code == 200
41+
logger.info(f"response: {response.json()}")

0 commit comments

Comments
 (0)