Skip to content

Commit 4493188

Browse files
author
RobuRishabh
committed
Add GitHub Actions CI workflow
1 parent e61dcb2 commit 4493188

File tree

6 files changed

+121
-0
lines changed

6 files changed

+121
-0
lines changed

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: CI Tests
2+
3+
# Trigger the workflow on pushes and pull requests to the main branch
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest # Use the latest Ubuntu runner
15+
16+
steps:
17+
# Step 1: Checkout the repository code
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
# Step 2: Set up Python environment
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.11' # Specify your Python version
26+
27+
# Step 3: Install dependencies
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -r requirements.txt
32+
33+
# Step 4: Run unit tests
34+
- name: Run tests
35+
run: |
36+
python -m unittest discover -s tests -p "test_*.py"
37+
38+
# Optional: Cache dependencies to speed up future runs
39+
- name: Cache dependencies
40+
uses: actions/cache@v3
41+
with:
42+
path: ~/.cache/pip
43+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
44+
restore-keys: |
45+
${{ runner.os }}-pip-

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pillow
3131
pydantic
3232
python-dateutil
3333
python-dotenv
34+
pytest
3435
PyYAML
3536
requests
3637
scikit-learn

tests/test_app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
from app import app # Assuming Flask or similar backend
3+
4+
class TestApp(unittest.TestCase):
5+
def setUp(self):
6+
self.app = app.test_client()
7+
self.app.testing = True
8+
9+
def test_homepage_loads(self):
10+
response = self.app.get("/")
11+
self.assertEqual(response.status_code, 200)
12+
13+
if __name__ == "__main__":
14+
unittest.main()

tests/test_mock_databse.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
from mock_database import flights
3+
4+
class TestMockDatabase(unittest.TestCase):
5+
def test_flight_data_exists(self):
6+
self.assertGreater(len(flights), 0, "Flight database should not be empty")
7+
8+
def test_flight_structure(self):
9+
flight = flights[0]
10+
expected_keys = {"flight_number", "origin", "destination", "time"}
11+
self.assertEqual(set(flight.keys()), expected_keys, "Flight data has incorrect structure")
12+
13+
if __name__ == "__main__":
14+
unittest.main()

tests/test_ollama_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import unittest
2+
from unittest.mock import patch
3+
from ollama_api import call_ollama_api
4+
5+
class TestOllamaAPI(unittest.TestCase):
6+
@patch("ollama_api.requests.post")
7+
def test_call_ollama_api_success(self, mock_post):
8+
mock_post.return_value.status_code = 200
9+
mock_post.return_value.json.return_value = {"response": "Flight NY100 departs at 08:00."}
10+
query = "What are flights from New York to London?"
11+
flight_data = [{"flight_number": "NY100", "origin": "New York", "destination": "London", "time": "2025-05-01 08:00"}]
12+
response = call_ollama_api(query, flight_data)
13+
self.assertEqual(response, "Flight NY100 departs at 08:00.")
14+
15+
@patch("ollama_api.requests.post")
16+
def test_call_ollama_api_failure(self, mock_post):
17+
mock_post.return_value.status_code = 500
18+
query = "What are flights from New York to London?"
19+
flight_data = [{"flight_number": "NY100", "origin": "New York", "destination": "London", "time": "2025-05-01 08:00"}]
20+
with self.assertRaises(Exception):
21+
call_ollama_api(query, flight_data)
22+
23+
if __name__ == "__main__":
24+
unittest.main()

tests/test_query_handler.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import unittest
2+
from query_handler import parse_query, search_flights
3+
4+
class TestQueryHandler(unittest.TestCase):
5+
def test_parse_query(self):
6+
query = "What flights are from New York to London?"
7+
result = parse_query(query)
8+
self.assertEqual(result["origin"], "New York")
9+
self.assertEqual(result["destination"], "London")
10+
11+
def test_search_flights(self):
12+
query = {"origin": "New York", "destination": "London"}
13+
results = search_flights(query)
14+
self.assertGreater(len(results), 0, "Should find at least one matching flight")
15+
self.assertIn("NY100", [f["flight_number"] for f in results])
16+
17+
def test_no_results(self):
18+
query = {"origin": "Mars", "destination": "Jupiter"}
19+
results = search_flights(query)
20+
self.assertEqual(len(results), 0, "Should return no results for invalid query")
21+
22+
if __name__ == "__main__":
23+
unittest.main()

0 commit comments

Comments
 (0)