From de927a6a047a33f2106677d496929213b132859b Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 15:18:37 +0530 Subject: [PATCH 1/5] chore: add .env.example file --- .env.example | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..6dcac11 --- /dev/null +++ b/.env.example @@ -0,0 +1 @@ +MONGO_URI="mongodb+srv://:@/?retryWrites=true&w=majority" \ No newline at end of file From 423d948a5425c55ec4ca7abc22fda3214a9a0a37 Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 15:20:44 +0530 Subject: [PATCH 2/5] ci: add GitHub Actions workflow (ci.yml) --- .github/workflows/ci.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..322d6ef --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: Backend CI/CD Workflow + +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + + - name: Install Dependencies + run: pip install -r requirements.txt + + - name: Run Tests (with MockDB) + env: + TESTING: "True" + run: pytest tests/ + + build: + runs-on: ubuntu-latest + needs: test + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Build Docker Image + run: docker build -t suraksha-backend:latest . From be5c43aab92244d4d303893b4b210ddc5947018a Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 15:23:07 +0530 Subject: [PATCH 3/5] test: add MongoDB mock for testing --- db/mongo.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/db/mongo.py b/db/mongo.py index 0bca777..316ec75 100644 --- a/db/mongo.py +++ b/db/mongo.py @@ -8,11 +8,16 @@ try: MONGO_URI = os.getenv("MONGO_URI", "mongodb://localhost:27017/") - client = MongoClient(MONGO_URI) + if os.getenv("TESTING") == "True": + import mongomock + client = mongomock.MongoClient() + print("Connected to MongoMock for testing.") + else: + client = MongoClient(MONGO_URI) # Test connection - client.admin.command('ping') - print("Connected successfully to MongoDB") + client.admin.command('ping') + print("Connected successfully to MongoDB") db = client["earnsure"] From 0f4022e266cf23f392b79c7c91347ecfc1713a23 Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 15:24:15 +0530 Subject: [PATCH 4/5] test: add mongomock dependency --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 482da88..d09d406 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ requests==2.31.0 numpy==1.26.2 pytest==7.4.3 python-dotenv==1.0.0 +mongomock==4.1.2 \ No newline at end of file From 96642d8283eac405083b340ea7068c0fcfee2e46 Mon Sep 17 00:00:00 2001 From: Yogini Aishwaryaa P T S Date: Sat, 4 Apr 2026 15:25:50 +0530 Subject: [PATCH 5/5] build: add Dockerfile for application --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..cd29d0a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:3.10-slim +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY . . +# Optional: if you need port 5000 internally +EXPOSE 5000 +CMD ["python", "app.py"]