-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for flask api and the first /analyze endpoint
- Loading branch information
1 parent
56d1452
commit 5c60000
Showing
3 changed files
with
59 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
import json | ||
|
||
from app import Server | ||
|
||
@pytest.fixture() | ||
def app(): | ||
app = Server().app | ||
app.config.update({ | ||
"TESTING": True, | ||
}) | ||
|
||
yield app | ||
|
||
|
||
@pytest.fixture() | ||
def client(app): | ||
return app.test_client() | ||
|
||
|
||
def test_health(client): | ||
response = client.get("/health") | ||
assert response.status_code == 200 | ||
|
||
|
||
def test_analyze_csv_file(client): | ||
expected_response_id = {'value': ['1', '2', '3'], 'recognizer_results': [[], [], []]} | ||
|
||
response = client.post("/analyze", data={ | ||
"file": open('./tests/analyzer_engine/sample_data.csv', 'rb'), | ||
}) | ||
|
||
assert response.status_code == 200 | ||
data = json.loads(response.get_data(as_text=True)) | ||
# No PII in id | ||
assert data['id'] == expected_response_id | ||
# first row has no PII | ||
assert data['comments']['recognizer_results'][0] == [] | ||
# second row has PII | ||
assert data['comments']['recognizer_results'][1][0]['entity_type'] == 'US_DRIVER_LICENSE' | ||
assert data['comments']['recognizer_results'][1][0]['start'] == 34 | ||
assert data['comments']['recognizer_results'][1][0]['end'] == 42 |