From 6303682fcdd5dbfd0319448b39960919f7d3b0c1 Mon Sep 17 00:00:00 2001 From: SarahWohlford <157171746+SarahWohlford@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:26:09 -0400 Subject: [PATCH 1/8] Updated Tests --- tests/test_departments.py | 45 +++++++++++++++++++++++++++++++++++++++ tests/test_lab_manager.py | 1 + tests/test_user.py | 16 +++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/tests/test_departments.py b/tests/test_departments.py index 445cd3c1..4d3dd497 100644 --- a/tests/test_departments.py +++ b/tests/test_departments.py @@ -37,11 +37,52 @@ def test_departments_route(test_client: FlaskClient) -> None: "space, the final frontier", "flying, need for speed", ), + ( + "School of science", + "School of science", + "School of engineering", + "School of science", + "School of engineering", + "School of engineering", + "School of engineering", + ), + ( + "CSCI", + "BIOL", + "MTLE" + "MATH", + "ENVI", + "MANE", + "MANE", + ), + ( + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png" + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + "https://cdn-icons-png.flaticon.com/512/5310/5310672.png", + ), + ( + "https://www.rpi.edu", + "https://www.rpi.edu", + "https://www.rpi.edu", + "https://www.rpi.edu", + "https://www.rpi.edu", + "https://www.rpi.edu", + "https://www.rpi.edu", + ), ) for department in json_data: assert department["name"] in rpi_departments_data[0] assert department["description"] in rpi_departments_data[1] + #Added + assert department["school_id"] in rpi_departments_data[2] + assert department["id"] in rpi_departments_data[3] + assert department["image"] in rpi_departments_data[4] + assert department["webcite"] in rpi_departments_data[5] def test_department_route(test_client: FlaskClient) -> None: @@ -59,6 +100,10 @@ def test_department_route(test_client: FlaskClient) -> None: assert json_data["name"] == "Computer Science" assert json_data["description"] == "DS" assert json_data["school_id"] == "School of Science" + #Added + assert json_data["id"] == "CSCI" + assert json_data["image"] == "https://cdn-icons-png.flaticon.com/512/5310/5310672.png" + assert json_data["webcite"] == "https://www.rpi.edu" prof_names = ["Duy Le", "Rafael", "Turner", "Kuzmin", "Goldschmidt"] prof_rcs_ids = ["led", "cenzar", "turner", "kuzmin", "goldd"] diff --git a/tests/test_lab_manager.py b/tests/test_lab_manager.py index 0cea0a03..7e288834 100644 --- a/tests/test_lab_manager.py +++ b/tests/test_lab_manager.py @@ -25,6 +25,7 @@ def test_lab_manager_route_with_input_id(test_client: FlaskClient) -> None: "alt_email": None, "phone_number": None, "email": None, + "description": None, } assert json_data == cenzar_data diff --git a/tests/test_user.py b/tests/test_user.py index ab075777..d1e7d40a 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -20,9 +20,17 @@ def test_user_route_with_input_id_1(test_client: FlaskClient) -> None: assert json_data["id"] == 1 assert json_data["first_name"] == "Rafael" - assert json_data["last_name"] == "Cenzano" assert json_data["preferred_name"] == "Raf" + assert json_data["last_name"] == "Cenzano" assert json_data["email"] == "cenzar@rpi.edu" + #Added + assert json_data["description"] == "labconnect is the best RCOS project" + assert json_data["profile_picture"] == "https://rafael.sirv.com/Images/rafael.jpeg?thumbnail=350&format=webp&q=90" + assert json_data["website"] == "https://rafaelcenzano.com" + #class year + assert json_data["class_year"] == "2025" + #lab manager id + assert json_data["lab_manager_id"] == 1 departments_data = [ {"user_id": 1, "department_id": "Computer Science"}, @@ -104,6 +112,12 @@ def test_user_route_with_input_id_2(test_client: FlaskClient) -> None: assert json_data["last_name"] == "RCOS" assert json_data["preferred_name"] is None assert json_data["email"] == "test@rpi.edu" + #Added + assert json_data["description"] is None + assert json_data["profile_picture"] == "https://www.svgrepo.com/show/206842/professor.svg" # Adjust based on your test data + assert json_data["website"] is None + assert json_data["class_year"] is None + assert json_data["lab_manager_id"] is None departments_data = [ {"department_id": "Computer Science", "user_id": 2}, From 8f97033a66b16d326d807c0adf43d3ea6fa7d4a4 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 18:52:25 -0500 Subject: [PATCH 2/8] format with black --- tests/test_departments.py | 13 +++++++------ tests/test_user.py | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/tests/test_departments.py b/tests/test_departments.py index 4d3dd497..7f64ac18 100644 --- a/tests/test_departments.py +++ b/tests/test_departments.py @@ -39,7 +39,7 @@ def test_departments_route(test_client: FlaskClient) -> None: ), ( "School of science", - "School of science", + "School of science", "School of engineering", "School of science", "School of engineering", @@ -49,8 +49,7 @@ def test_departments_route(test_client: FlaskClient) -> None: ( "CSCI", "BIOL", - "MTLE" - "MATH", + "MTLE" "MATH", "ENVI", "MANE", "MANE", @@ -78,7 +77,7 @@ def test_departments_route(test_client: FlaskClient) -> None: for department in json_data: assert department["name"] in rpi_departments_data[0] assert department["description"] in rpi_departments_data[1] - #Added + # Added assert department["school_id"] in rpi_departments_data[2] assert department["id"] in rpi_departments_data[3] assert department["image"] in rpi_departments_data[4] @@ -100,9 +99,11 @@ def test_department_route(test_client: FlaskClient) -> None: assert json_data["name"] == "Computer Science" assert json_data["description"] == "DS" assert json_data["school_id"] == "School of Science" - #Added + # Added assert json_data["id"] == "CSCI" - assert json_data["image"] == "https://cdn-icons-png.flaticon.com/512/5310/5310672.png" + assert ( + json_data["image"] == "https://cdn-icons-png.flaticon.com/512/5310/5310672.png" + ) assert json_data["webcite"] == "https://www.rpi.edu" prof_names = ["Duy Le", "Rafael", "Turner", "Kuzmin", "Goldschmidt"] diff --git a/tests/test_user.py b/tests/test_user.py index d1e7d40a..122a7c63 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -23,13 +23,16 @@ def test_user_route_with_input_id_1(test_client: FlaskClient) -> None: assert json_data["preferred_name"] == "Raf" assert json_data["last_name"] == "Cenzano" assert json_data["email"] == "cenzar@rpi.edu" - #Added + # Added assert json_data["description"] == "labconnect is the best RCOS project" - assert json_data["profile_picture"] == "https://rafael.sirv.com/Images/rafael.jpeg?thumbnail=350&format=webp&q=90" + assert ( + json_data["profile_picture"] + == "https://rafael.sirv.com/Images/rafael.jpeg?thumbnail=350&format=webp&q=90" + ) assert json_data["website"] == "https://rafaelcenzano.com" - #class year + # class year assert json_data["class_year"] == "2025" - #lab manager id + # lab manager id assert json_data["lab_manager_id"] == 1 departments_data = [ @@ -112,10 +115,13 @@ def test_user_route_with_input_id_2(test_client: FlaskClient) -> None: assert json_data["last_name"] == "RCOS" assert json_data["preferred_name"] is None assert json_data["email"] == "test@rpi.edu" - #Added - assert json_data["description"] is None - assert json_data["profile_picture"] == "https://www.svgrepo.com/show/206842/professor.svg" # Adjust based on your test data - assert json_data["website"] is None + # Added + assert json_data["description"] is None + assert ( + json_data["profile_picture"] + == "https://www.svgrepo.com/show/206842/professor.svg" + ) # Adjust based on your test data + assert json_data["website"] is None assert json_data["class_year"] is None assert json_data["lab_manager_id"] is None From 483131f3e0e89e909690e94a31da295cb3aefb44 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 19:03:11 -0500 Subject: [PATCH 3/8] add postgres to pytest gh action --- .github/workflows/pytest.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 91267bca..e4bea05f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -9,6 +9,20 @@ on: jobs: build: runs-on: ubuntu-latest + services: + postgres: + image: postgres:16 + env: + POSTGRES_USER: test_user + POSTGRES_PASSWORD: test_password + POSTGRES_DB: test_db + ports: + - 5432:5432 + options: >- + --health-cmd="pg_isready -U test_user -d test_db" + --health-interval=10s + --health-timeout=5s + --health-retries=3 strategy: matrix: python-version: ["3.12.4"] @@ -22,9 +36,19 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Setup the Database + - name: Wait for PostgreSQL to be ready + run: | + while ! pg_isready -h localhost -p 5432 -U test_user -d test_db; do + echo "Waiting for PostgreSQL..." + sleep 2 + done + - name: Set up the Database + env: + DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db run: | python db_init.py create - name: Running pytest + env: + DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db run: | python -m pytest tests/ From 4c9b8bb354b31811a31f4cf00d1603d0b06e6187 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:12:04 -0500 Subject: [PATCH 4/8] adjust issues --- .github/workflows/pytest.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index e4bea05f..15ce8e69 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -36,12 +36,12 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - - name: Wait for PostgreSQL to be ready - run: | - while ! pg_isready -h localhost -p 5432 -U test_user -d test_db; do - echo "Waiting for PostgreSQL..." - sleep 2 - done + - name: Wait for PostgreSQL to be ready + run: | + while ! pg_isready -h localhost -p 5432 -U test_user -d test_db; do + echo "Waiting for PostgreSQL..." + sleep 2 + done - name: Set up the Database env: DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db From f5121a14d15131d5ca3e6fe1b75ecf4affde1f71 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:27:46 -0500 Subject: [PATCH 5/8] test connection --- .github/workflows/pytest.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 15ce8e69..6dbf853f 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -42,6 +42,9 @@ jobs: echo "Waiting for PostgreSQL..." sleep 2 done + - name: Test Database Connection + run: | + PGPASSWORD="test_password" psql -h localhost -p 5432 -U test_user -d test_db -c '\conninfo' - name: Set up the Database env: DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db From 0594ae8c9677d35eb5ac0ce89c3be849cb866c56 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:38:50 -0500 Subject: [PATCH 6/8] attempt to fix postgres test --- .github/workflows/pytest.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 6dbf853f..70337462 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -13,13 +13,13 @@ jobs: postgres: image: postgres:16 env: - POSTGRES_USER: test_user - POSTGRES_PASSWORD: test_password + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres POSTGRES_DB: test_db ports: - 5432:5432 options: >- - --health-cmd="pg_isready -U test_user -d test_db" + --health-cmd="pg_isready -U postgres -d test_db" --health-interval=10s --health-timeout=5s --health-retries=3 @@ -38,20 +38,17 @@ jobs: pip install -r requirements.txt - name: Wait for PostgreSQL to be ready run: | - while ! pg_isready -h localhost -p 5432 -U test_user -d test_db; do + while ! pg_isready -h localhost -p 5432 -U postgres -d test_db; do echo "Waiting for PostgreSQL..." sleep 2 done - - name: Test Database Connection - run: | - PGPASSWORD="test_password" psql -h localhost -p 5432 -U test_user -d test_db -c '\conninfo' - name: Set up the Database env: - DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db + DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db run: | python db_init.py create - name: Running pytest env: - DATABASE_URL: postgres://test_user:test_password@localhost:5432/test_db + DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db run: | python -m pytest tests/ From 1d70cc0406aa2e5ec2f452ab89264aa33930729b Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:43:27 -0500 Subject: [PATCH 7/8] try removing password --- .github/workflows/pytest.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 70337462..22715083 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -14,7 +14,6 @@ jobs: image: postgres:16 env: POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres POSTGRES_DB: test_db ports: - 5432:5432 @@ -44,11 +43,11 @@ jobs: done - name: Set up the Database env: - DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db + DATABASE_URL: postgres://postgres@localhost:5432/test_db run: | python db_init.py create - name: Running pytest env: - DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db + DATABASE_URL: postgres://postgres@localhost:5432/test_db run: | python -m pytest tests/ From 81dd667e9bc56ce9144afdda1e26bc26005c70c8 Mon Sep 17 00:00:00 2001 From: Rafael Cenzano <32753063+RafaelCenzano@users.noreply.github.com> Date: Fri, 22 Nov 2024 23:50:59 -0500 Subject: [PATCH 8/8] fix url --- .github/workflows/pytest.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 22715083..b7fdd24b 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -14,11 +14,12 @@ jobs: image: postgres:16 env: POSTGRES_USER: postgres - POSTGRES_DB: test_db + POSTGRES_PASSWORD: postgres_password + POSTGRES_DB: labconnect ports: - 5432:5432 options: >- - --health-cmd="pg_isready -U postgres -d test_db" + --health-cmd="pg_isready -U postgres -d labconnect" --health-interval=10s --health-timeout=5s --health-retries=3 @@ -37,17 +38,17 @@ jobs: pip install -r requirements.txt - name: Wait for PostgreSQL to be ready run: | - while ! pg_isready -h localhost -p 5432 -U postgres -d test_db; do + while ! pg_isready -h localhost -p 5432 -U postgres -d labconnect; do echo "Waiting for PostgreSQL..." sleep 2 done - name: Set up the Database env: - DATABASE_URL: postgres://postgres@localhost:5432/test_db + DATABASE_URL: postgresql+psycopg2://postgres:postgres_password@localhost/labconnect run: | python db_init.py create - name: Running pytest env: - DATABASE_URL: postgres://postgres@localhost:5432/test_db + DATABASE_URL: postgresql+psycopg2://postgres:postgres_password@localhost/labconnect run: | python -m pytest tests/