Skip to content

Commit

Permalink
add a language parameter and move test files in a sample_data dir
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaykarle committed May 30, 2024
1 parent 7bc68b9 commit e79506d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def analyze() -> Tuple[str, int]:
"""Execute the analyzer function."""
try:
file = request.files['file']
language = request.form['language']
if file.filename == '':
return jsonify({'error': 'No selected file'}), 400

Expand All @@ -46,7 +47,7 @@ def analyze() -> Tuple[str, int]:

analyzer_results = self.engine.analyze_csv(
csv_full_path=filepath,
language="en"
language=language
)
self.logger.debug(f"Analyzed file with results: {analyzer_results}")
os.remove(filepath)
Expand Down
2 changes: 1 addition & 1 deletion tests/analyzer_engine/csv_analyzer_engine_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_csv_analyzer_engine_anonymizer():
nlp_engine = FlairNLPEngine("flair/ner-english-large")
csv_analyzer = CSVAnalyzerEngine(nlp_engine)
from presidio_anonymizer import BatchAnonymizerEngine
analyzer_results = csv_analyzer.analyze_csv('./sample_data.csv', language="en")
analyzer_results = csv_analyzer.analyze_csv('../sample_data/sample_data.csv', language="en")

anonymizer = BatchAnonymizerEngine()
anonymized_results = anonymizer.anonymize_dict(analyzer_results)
Expand Down
20 changes: 18 additions & 2 deletions tests/app_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,28 @@ def test_health(client):
response = client.get("/health")
assert response.status_code == 200

def test_analyze_non_existent(client):
response = client.post("/analyze", data={
"language": "en",
})

assert response.status_code == 500


def test_analyze_invalid_csv(client):
response = client.post("/analyze", data={
"file": open('./tests/sample_data/invalid.csv', 'rb'),
})

assert response.status_code == 500


def test_analyze_csv_file(client):
def test_analyze_pii_csv(client):
expected_response_id = {'value': ['1', '2', '3'], 'recognizer_results': [[], [], []]}

response = client.post("/analyze", data={
"file": open('./tests/analyzer_engine/sample_data.csv', 'rb'),
"file": open('./tests/sample_data/sample_data.csv', 'rb'),
"language": "en",
})

assert response.status_code == 200
Expand Down
3 changes: 3 additions & 0 deletions tests/sample_data/invalid.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"hello": "json"
}
File renamed without changes.

0 comments on commit e79506d

Please sign in to comment.