diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml new file mode 100644 index 0000000..570ede2 --- /dev/null +++ b/.github/workflows/ci-cd.yaml @@ -0,0 +1,32 @@ +name: Run Tests + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + name: Test FastAPI Application + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Run Tests + run: | + pytest test_main.py diff --git a/.gitignore b/.gitignore index 2825d16..815cb55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__/ venv/ -.env \ No newline at end of file +.env +.pytest_cache/ \ No newline at end of file diff --git a/api.py b/api.py index 0d820c8..c392e3f 100644 --- a/api.py +++ b/api.py @@ -145,7 +145,7 @@ async def health_app_gemini(image_file: UploadFile = File(...), height: str = Fo mongo_data = {"Document": payload} result = db.insert_data(mongo_data) print(result) - return JSONResponse(content=json_compatible_data) + return ResponseText(response=json_compatible_data) @app.post("/blog_generator",description="This route will generate the blog based on the desired topic.") async def blogs(topic: str = Form("Generative AI")): diff --git a/data/burger.jpg b/data/burger.jpg new file mode 100644 index 0000000..a6b9c9f Binary files /dev/null and b/data/burger.jpg differ diff --git a/data/invoice.png b/data/invoice.png new file mode 100644 index 0000000..738c9b4 Binary files /dev/null and b/data/invoice.png differ diff --git a/requirements.txt b/requirements.txt index 180c08c..11bcd82 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,8 +9,8 @@ python-dotenv python-multipart PyPDF2 unstructured -# python-magic-bin==0.4.14 this lib is not for linux os youtube_transcript_api llama-index pypdf -pymongo \ No newline at end of file +pymongo +pytest \ No newline at end of file diff --git a/test_main.py b/test_main.py new file mode 100644 index 0000000..6226090 --- /dev/null +++ b/test_main.py @@ -0,0 +1,61 @@ +from fastapi.testclient import TestClient +from api import app +from mongo import MongoDB + +client = TestClient(app) +db = MongoDB() + + +def test_invoice_extractor(): + image_file = open("data\invoice.png", "rb") + files = {"image_file": image_file} + data = {"prompt": "To whom this invoice belongs"} + + response = client.post("/invoice_extractor", files=files, data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_blogs(): + data = {"topic": "Tensorflow"} + + response = client.post("/blog_generator", data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_sql_query(): + data = {"prompt": "Tell me the employees living in city Noida"} + + response = client.post("/Text2SQL", data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_youtube_video_transcribe_summarizer(): + data = {"url": "https://www.youtube.com/watch?v=voexVsTHPBY&ab_channel=NabeelNawab"} + + response = client.post("/youtube_video_transcribe_summarizer", data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_nutritionist_expert(): + image_file = open(r"data\burger.jpg", "rb") + data = {"height": "165", "weight": "70"} + + response = client.post("/nutritionist_expert", files={"image_file": image_file}, data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_talk2PDF(): + pdf_file = open(r"data\yolo.pdf", "rb") + data = {"prompt": "Summary in 200 words"} + + response = client.post("/talk2PDF", files={"pdf": pdf_file}, data=data) + assert response.status_code == 200 + assert "response" in response.json() + +def test_questions_generator(): + pdf_file = open(r"data\yolo.pdf", "rb") + + # Make a request to the questions_generator endpoint + response = client.post("/questions_generator", files={"pdf": pdf_file}) + assert response.status_code == 200 + assert "response" in response.json() \ No newline at end of file