From f9dff3fc140f2353daaa4e229bd3546da67e9009 Mon Sep 17 00:00:00 2001 From: rabeeafaraj Date: Sat, 9 Aug 2025 21:22:54 +0300 Subject: [PATCH] api_changes --- .github/workflows/api-tests.yaml | 19 ++++++++++++------- tests_r/test_endpoint.py | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/api-tests.yaml b/.github/workflows/api-tests.yaml index 609122ca6..e25a85f28 100644 --- a/.github/workflows/api-tests.yaml +++ b/.github/workflows/api-tests.yaml @@ -29,19 +29,24 @@ jobs: docker compose up -d sleep 10 - - name: Wait for API to be ready + - name: Wait for API /users/login to be ready run: | - echo "Waiting for API at localhost:80..." - for i in {1..10}; do - if curl -s http://localhost:80 >/dev/null; then - echo "API is up!" + echo "Checking /users/login endpoint readiness..." + for i in {1..15}; do + status_code=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:80/users/login) + if [ "$status_code" = "400" ] || [ "$status_code" = "200" ]; then + echo "API /users/login responded with status $status_code" exit 0 fi - echo "Retry $i..." + echo "Retry $i: API not ready yet, status $status_code" sleep 3 done - echo "API did not start in time." + echo "API /users/login did not become ready in time." exit 1 + - name: Seed DB with test user + run: | + docker exec your_api_container_name python3 seed_users.py + - name: Run pytest run: pytest tests_r/ --maxfail=1 --disable-warnings -v diff --git a/tests_r/test_endpoint.py b/tests_r/test_endpoint.py index 656d6b84a..f6beaafe5 100644 --- a/tests_r/test_endpoint.py +++ b/tests_r/test_endpoint.py @@ -10,6 +10,8 @@ class TestUserLogin(unittest.TestCase): "password": "30fnhk03" } response = requests.post(url, json=payload) + print("Status code:", response.status_code) + print("Response JSON:", response.json()) self.assertEqual(response.status_code, 200) self.assertIn("token", response.json())