From b82a383be34f5ec4305daf3c965d4b3bdc35e6d0 Mon Sep 17 00:00:00 2001 From: lerina07 Date: Sun, 26 Oct 2025 16:07:17 +0530 Subject: [PATCH 1/5] Add unit tests for endpoints, data processing, and integration --- .../conftest.cpython-312-pytest-8.4.2.pyc | Bin 0 -> 650 bytes ...ata_processing.cpython-312-pytest-8.4.2.pyc | Bin 0 -> 1144 bytes ...test_endpoints.cpython-312-pytest-8.4.2.pyc | Bin 0 -> 3894 bytes ...st_integration.cpython-312-pytest-8.4.2.pyc | Bin 0 -> 1322 bytes tests/conftest.py | 6 ++++++ tests/test_data_processing.py | 4 ++++ tests/test_endpoints.py | 17 +++++++++++++++++ tests/test_integration.py | 4 ++++ 8 files changed, 31 insertions(+) create mode 100644 tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/__pycache__/test_data_processing.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/__pycache__/test_integration.cpython-312-pytest-8.4.2.pyc create mode 100644 tests/conftest.py create mode 100644 tests/test_data_processing.py create mode 100644 tests/test_endpoints.py create mode 100644 tests/test_integration.py diff --git a/tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/conftest.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7d59b6b1d46bac1e20e8e81ccac7a8bebc6d5ef6 GIT binary patch literal 650 zcmX@j%ge<81cE>QX6yvgk3k$5V23h3GcYnROlL@8NMX!jh++iOOu5X-OpFY$mm5iE9FF_nXO}<+kNu`-NC7F4}w|E>1D&yfi$@qfGlGNf7y~N_;)S{Bi z{5-v))bgUtlGIzAaG_i5FflHmW{~pu#G+eF`Ng-Giz|z7u@oehWZYs;$t=oC%uT(; zo|se&7U77GPs_|njgP;@Q&5zjm6}`r89swt_siGWDkc;tP#oiv zT9lcWsNj-Wo|utX6yuUwoL!P%5EBsO@8#+o5*!m;SzMBu>zkjKS&|P_nXYRX19D7p zOmco+8rT;FmA^P_a`RJ4b5iY!M1ZD)Lbcc*NPJ*sWMsV0z|g|b%z2xE>jN8ufKY#V zXL)~pXZ?(#`QK!xtXVy*2#jVNtBh*oR$&=Odt*-f+Uelat#O-Z0g z4~m!GMDXNI`lopD6J-!Qc*;%8tswYjHk+j2BYE%lW`6Hu-rM&>Ljwq8_Rrs{1@@P8 z645%KeF4BLWFs4UXay^)`FdHy$TwC}7}?q`T1nTjskdavLb(&DOa`+GFO~+{@8Bl3wWij<4Q*o_p{Cx@*=sIim8=^H>RB5&6>J+arlRe47@aDeFpp4!cD!Y)sdN7fR)JMw&X5bvZ)qSLnc1ZibWG|AHO&r z)i0Z@P%IWCoHCh6Q-{?&ZfZh@JE^9&hY4d2<%%;695|ddb3$h|Uku!e>fB-6B2*l+ z%Ea?5>O{00`Vpay7=&wUwdQ)<4IsG}0)vTD7ORFe&sJ1x%?nqFX9dJ}M9yNQ;>ZkQ z__nI*hQU0gAr&XAN=SXeEoUq8NI*E;m}z0ygcF*BcZnmiSlsKCerGav;_$2e&J2?S zDJVHup1oFj0uN=Sdk%F2QkZi$NtMvjoWnMF7?mDAdT@7s_VH3_sm{3L-wy+qhrnFB zG+B}}U`kuEAuFO`*JrT8m%~1~M7JI>_GeL%ZfVH|cqB)zjo>{9DHu O|3qjPwULfbs(^oD2@;Y3 literal 0 HcmV?d00001 diff --git a/tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc b/tests/__pycache__/test_endpoints.cpython-312-pytest-8.4.2.pyc new file mode 100644 index 0000000000000000000000000000000000000000..509d6c4ff9c52d83f3725234b12365dc3851c568 GIT binary patch literal 3894 zcmeGfU2GIZcxHEdyLZ?23M~q1=p_p2J+LjbNHLyh3JD^j5sb;D$+~o>?H+r#mzk|_ z^)7-T0fGteR33PMC%h07dE!;yOnm9l7RaD6#wXs4eKAc;{ATy&_8=vim}p{{+teP011>_(Hd#HfJSt+Sg3PvTZ(1nFW z@e(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#(a6W0iJYb$UJ&j?{g%Mt#7NFIO< z@V(+Hucw`xY3D}l#Hntjo!gZEQ;P98TA035U4VvZ^^rwv&nV8=o5qSksxuZ{3;m$_ z^x2b#v(wM#tMd&STJB@tvqK-0%U4TPejrq!ZhN7%OhmEcL4%Eovq}Y_8^aA8i=2ba z`Ln050JhPgn%|y0R0{wDgS+c{<@cG9{V9Om^8VD`-LIJu_<})o7h<_?jPO@1 qdVGt>dCt!Q9I5wQ-`sGl`{W|HqJ92Wf65r+ZwT$64wCU{vEUDOMJ|*8 literal 0 HcmV?d00001 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..85d7212 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,6 @@ +import os +import sys + +# Get the parent directory of tests (project root) +project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.insert(0, project_root) \ No newline at end of file diff --git a/tests/test_data_processing.py b/tests/test_data_processing.py new file mode 100644 index 0000000..87983b5 --- /dev/null +++ b/tests/test_data_processing.py @@ -0,0 +1,4 @@ +def test_sample_data(): + data = [1, 2, 3] + result = sum(data) + assert result == 6 diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py new file mode 100644 index 0000000..d287c1c --- /dev/null +++ b/tests/test_endpoints.py @@ -0,0 +1,17 @@ +from fastapi.testclient import TestClient +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +from apps import app + +client = TestClient(app) + +def test_root_endpoint(): + response = client.get("/") + assert response.status_code == 200 + assert response.json() == {"message": "Hello World"} # matches your code + +def test_health_endpoint(): + response = client.get("/health") + assert response.status_code == 200 + assert response.json() == {"status": "ok"} # matches your code diff --git a/tests/test_integration.py b/tests/test_integration.py new file mode 100644 index 0000000..4911aeb --- /dev/null +++ b/tests/test_integration.py @@ -0,0 +1,4 @@ +def test_integration_example(): + x = 5 + y = 10 + assert x + y == 15 From 6e8814817e1c91964761a2476513cadd24e2dd5d Mon Sep 17 00:00:00 2001 From: lerina07 Date: Sun, 26 Oct 2025 16:10:26 +0530 Subject: [PATCH 2/5] Add unit tests for endpoints, data processing, and integration --- SystemMonitoring | 1 + __pycache__/__init__.cpython-312.pyc | Bin 0 -> 168 bytes __pycache__/apps.cpython-312.pyc | Bin 0 -> 844 bytes 3 files changed, 1 insertion(+) create mode 160000 SystemMonitoring create mode 100644 __pycache__/__init__.cpython-312.pyc create mode 100644 __pycache__/apps.cpython-312.pyc diff --git a/SystemMonitoring b/SystemMonitoring new file mode 160000 index 0000000..93769c8 --- /dev/null +++ b/SystemMonitoring @@ -0,0 +1 @@ +Subproject commit 93769c8898407deda1c4b5ac07672efbaa60c918 diff --git a/__pycache__/__init__.cpython-312.pyc b/__pycache__/__init__.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5e5f16f4f9b4240ab4b151f10eaae6bbf82a77e5 GIT binary patch literal 168 zcmX@j%ge<81b(0YW`O9&AOanHW&w&!XQ*V*Wb|9fP{ah}eFmxdzkjKS&|P_nXYRX6Ca-m nu*uC&Da}c>D`Ewj%Lv59AjU^#Mn=XWW*`dyMQ|%E literal 0 HcmV?d00001 diff --git a/__pycache__/apps.cpython-312.pyc b/__pycache__/apps.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7ef52f2c6d49531d4d5ea15b6ad1ad1dbfc85267 GIT binary patch literal 844 zcma)4&ubGw6n?X_-TZ1=q17VWLp;WY7f~1O-8jDecun>mqnB8PIv&?MJ6og6z zJ@%%5g3>?5%a#a*g+j%Xx0Kuhf-{?>iGtvRdGo#f-o78-?$>-i3)0GiU(OB!_@RP{ z;V~FQ5_|+3Y~+EDst75pd76)_7=Z>99gS0~x{UB7YUU=TrZ?4(WFKYC{OF$bQx*Z$ zn~SsD2-|q_zOBE5NvCT1AK7yk*~UzErkg6Jf2x8-6sH~#5#HO~mT+OaEkfS$X*(n# z<3qGjpPfLHff8k)G?RiLTXRtbintu7d@2NK(7oJ4>Upg2f^pCO0z9qK<$+Pca7)cq7|~h+I{-u(f!i1idE@~kou2V+m$o8?Z(a976}4zE9k}< zPKjOPjD=ijn~_H-8Ta9A{_^3QD7O~rYg|3vOKmumc%k#Z8yG_F+!3+HTFKNSr%G|P zZahCKSF1a;-s0-ZsKyuFmk;eIXGXf2bT1dPaq6Yil>{zVlEv2o&U_j=v?FR`qUQdg zHrG`imaE3uDH9v?b-)CTaf6PQPI~_}-7vlBGrQx_yZnl*qW&<^kgksrLZ@J!!sd4) zf8g%pa|6&~4=$a6c?{;KQV$9zuzn2dpYb=iafbBwD{ogmEFG+#YY1H*V9*x&3iS=p T<`V8|4=pKjRgudHN_PGYgM+xV literal 0 HcmV?d00001 From 7812e713078d741ace32ae47d36965636272ea80 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 16 Nov 2025 16:20:25 +0000 Subject: [PATCH 3/5] Updated Dockerfile --- Dockerfile | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 808ae13..c66dcc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,32 +1,22 @@ -# Use full Python image (not slim) to avoid missing system libs -FROM python:3.11 +FROM python:3.11-slim -# Set working directory WORKDIR /app -# Install required system dependencies for pandas & scikit-learn -RUN apt-get update && apt-get install -y \ - gcc \ - g++ \ - make \ +# Install minimal system dependencies +RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libopenblas-dev \ liblapack-dev \ gfortran \ && rm -rf /var/lib/apt/lists/* -# Copy requirements first to leverage Docker cache COPY req.txt . -# Upgrade pip and install Python dependencies -RUN pip install --upgrade pip setuptools wheel --no-cache-dir \ +RUN pip install --upgrade pip \ && pip install --no-cache-dir -r req.txt -# Copy application files COPY . . -# Expose FastAPI port EXPOSE 8000 -# Run FastAPI app CMD ["uvicorn", "apps:app", "--host", "0.0.0.0", "--port", "8000"] From e8252155fe6279e3417cb7b220e678067db317c7 Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 16 Nov 2025 16:20:46 +0000 Subject: [PATCH 4/5] Updated CI/CD --- .github/workflows/ci.yml | 24 ++++++++++++++++ .github/workflows/docker-build.yml | 30 ++++++++++++++++++++ .github/workflows/docker-image.yml | 44 ------------------------------ 3 files changed, 54 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/docker-build.yml delete mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..30528df --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,24 @@ +name: Python CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - name: Install dependencies + run: pip install -r req.txt + + - name: Syntax check + run: python -m py_compile $(find . -name "*.py") diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..0731374 --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,30 @@ +name: Docker Build & Push + +on: + push: + branches: [ "main" ] + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build & Push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: aryansharma04/systemmonitoring:latest + cache-from: type=registry,ref=aryansharma04/systemmonitoring:cache + cache-to: type=registry,ref=aryansharma04/systemmonitoring:cache,mode=max diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index cdbeb17..0000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: CI/CD Pipeline for Docker - -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - # 👇 Only log in to Docker Hub for non-pull-request events - - name: Log in to Docker Hub - if: github.event_name != 'pull_request' - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - # 👇 Skip message for PRs - - name: Skip Docker login on pull requests - if: github.event_name == 'pull_request' - run: echo "Skipping Docker login — secrets are unavailable in PRs." - - # 👇 Build and push Docker image - - name: Build and push Docker image - uses: docker/build-push-action@v5 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: aryansharma04/systemmonitoring:latest - - - name: Clean up images - run: docker image prune -af From a61ee514532673d5d7efb99855ffb94dc22890fe Mon Sep 17 00:00:00 2001 From: Aryan Sharma Date: Sun, 16 Nov 2025 16:32:58 +0000 Subject: [PATCH 5/5] Updated Dockerfile --- Dockerfile | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c66dcc1..503fe78 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,8 @@ -FROM python:3.11-slim +# ---------- Stage 1: Build dependencies ---------- +FROM python:3.11-slim AS builder WORKDIR /app -# Install minimal system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libopenblas-dev \ @@ -13,8 +13,18 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ COPY req.txt . RUN pip install --upgrade pip \ - && pip install --no-cache-dir -r req.txt + && pip install --no-cache-dir -r req.txt \ + && pip install --no-cache-dir uvicorn + +# ---------- Stage 2: Final lightweight image ---------- +FROM python:3.11-slim + +WORKDIR /app + +# Copy only installed packages (fast!) +COPY --from=builder /usr/local /usr/local +# Copy app code COPY . . EXPOSE 8000