Skip to content

Commit

Permalink
ADDED: Test cases of the api and CI-CD pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Mar 13, 2024
1 parent b3d2a03 commit d9b656f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci-cd.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
venv/
.env
.env
.pytest_cache/
2 changes: 1 addition & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")):
Expand Down
Binary file added data/burger.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/invoice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
pymongo
pytest
61 changes: 61 additions & 0 deletions test_main.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d9b656f

Please sign in to comment.