Skip to content

Commit ec35558

Browse files
Merge pull request #13 from UPstartDeveloper/testing
Testing
2 parents b612b31 + 3ad7648 commit ec35558

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ __pycache__/
1111
.vscode
1212

1313
# Keras Models
14-
*model/*
14+
model/
15+
16+
# Images Downloaded for Testing
17+
test-assets/
1518

1619
# Distribution / packaging
1720
.Python

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: python
2+
python:
3+
- "3.6"
4+
# command to install dependencies
5+
install:
6+
- pip install -r requirements.txt
7+
# command to run tests
8+
script:
9+
- pytest

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ We built this API to show how the technology can fight this and other crises, an
1111
### Use the API
1212
To classify your own images, you can use the live API: use the link [here](https://fire-detection-api.herokuapp.com/docs) to read the documentation and send requests.
1313

14-
### Run the Tests
15-
TBD
16-
1714
### Running Locally
1815

1916
#### Using Docker
@@ -35,6 +32,12 @@ And then run the app using `uvicorn` in the Command Line:
3532
(env) $ uvicorn app.main:app --reload
3633
```
3734

35+
### Run the Tests
36+
To run the tests, you will first need to set up a Python virtual environment to run this project locally (see above). Then you can run the automated tests from the root directory, using the command line:
37+
```
38+
(env) $ pytest
39+
```
40+
3841
## The Data and the Model
3942
The image dataset and model used for the production API will be documented on the [Releases](https://github.com/UPstartDeveloper/Fire-Detection-API/releases) page of this repository.
4043

app/__init__.py

Whitespace-only changes.

app/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
predictor = ImagePredictor.init_from_config_path(predictor_config_path)
1616

1717

18-
@app.post("/classify-image/", tags=["Detect Fire in an Image"])
19-
def create_upload_file(file: UploadFile = File(...)):
18+
@app.post("/detect-fire/", tags=["Detect Fire in an Image"])
19+
def make_prediction(file: UploadFile = File(...)):
2020
"""Predicts the possibility that a RBG image contains fire."""
2121
return predictor.predict_from_file(file.file)

app/main_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import unittest
2+
3+
from fastapi.testclient import TestClient
4+
import tensorflow as tf
5+
6+
from app.main import app
7+
8+
client = TestClient(app)
9+
10+
class ClassifierAPITest(unittest.TestCase):
11+
12+
TEST_COLOR_IMG_URL = "https://storage.googleapis.com/download.tensorflow.org/example_images/592px-Red_sunflower.jpg"
13+
14+
def test_make_prediction_normal(self):
15+
'''Client submits a RGB image and gets a valid response.'''
16+
# A: get image
17+
image_path = tf.keras.utils.get_file(
18+
origin=self.TEST_COLOR_IMG_URL,
19+
cache_dir=".", cache_subdir="./test-assets"
20+
)
21+
with open(image_path, 'rb') as f:
22+
# B: format a mock request
23+
files = {"file": (f.name, f, "multipart/form-data")}
24+
# C: make a request, and verify a valid prediction is returned
25+
response = client.post(
26+
'/detect-fire', files=files
27+
)
28+
assert response.status_code == 307

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ fastapi==0.49.0
44
opencv-python-headless==4.5.3.56
55
PyYAML==5.3
66
uvicorn
7+
pytest==6.2.5
78
python-multipart

0 commit comments

Comments
 (0)