generated from nyu-software-engineering/containerized-app-exercise
-
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.
- Loading branch information
1 parent
7839d7e
commit 09a00c4
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,77 @@ | ||
import sys | ||
import os | ||
import tempfile | ||
import pytest | ||
from flask import jsonify | ||
from flask import Flask | ||
from flask import render_template | ||
from app import app, collection | ||
|
||
|
||
@pytest.fixture | ||
def client(): | ||
app.config["TESTING"] = True | ||
with app.test_client() as client: | ||
yield client | ||
|
||
def test_root_page(client): | ||
client.application.testing = True # Set testing mode for the app | ||
|
||
response = client.get("/") | ||
assert response.status_code == 200 | ||
assert b"template to render root page" in response.data | ||
|
||
def test_display_results(client): | ||
response = client.get("/results") | ||
assert response.status_code == 200 | ||
assert b"Function to render the results page" in response.data | ||
|
||
|
||
def test_analyze_data(client, monkeypatch): | ||
# Mock the requests.post method | ||
def mock_post(*args, **kwargs): | ||
class MockResponse: | ||
@staticmethod | ||
def json(): | ||
return {"mocked": "response"} | ||
|
||
return MockResponse() | ||
|
||
monkeypatch.setattr("requests.post", mock_post) | ||
|
||
# Mock the request.files method | ||
with tempfile.NamedTemporaryFile(suffix=".wav") as temp_file: | ||
response = client.post("/analyzeData", data={"audio": (temp_file, "test.wav")}) | ||
assert response.status_code == 200 | ||
assert b"mocked" in response.data | ||
|
||
|
||
def test_analyze_data_no_audio(client): | ||
response = client.post("/analyzeData") | ||
assert response.status_code == 200 | ||
assert b"No audio file provided" in response.data | ||
|
||
|
||
def test_analyze_data_failed_request(client, monkeypatch): | ||
# Mock the requests.post method to simulate a failed request | ||
def mock_post(*args, **kwargs): | ||
class MockResponse: | ||
@staticmethod | ||
def json(): | ||
return {"error": "Mocked error"} | ||
|
||
return MockResponse() | ||
|
||
monkeypatch.setattr("requests.post", mock_post) | ||
|
||
# Mock the request.files method | ||
with tempfile.NamedTemporaryFile(suffix=".wav") as temp_file: | ||
response = client.post("/analyzeData", data={"audio": (temp_file, "test.wav")}) | ||
assert response.status_code == 500 | ||
assert b"Failed to send and process audio" in response.data | ||
|
||
|
||
# Add more tests as needed | ||
|
||
if __name__ == "__main__": | ||
pytest.main(["-v", "test_app.py", "--cov=web-app"]) |