From af7c67abf721ed88d97c039a078b26fe0a7b5617 Mon Sep 17 00:00:00 2001 From: Quan Pham Date: Mon, 12 Jan 2026 13:47:45 -0500 Subject: [PATCH 1/2] Use postgres for CI run_unit_tests The production Coldfront uses Postgres. The tests will now more accurately reflect the production environment. Local testing can still be done with SQLite by not setting the `DB_URL` environment variable. A Postgres-specific bug was found regarding creating Field Of Science entries. More details in `tests/unit/test_migrate_field_of_science.py`. --- .github/workflows/test-functional-microshift.yaml | 1 + .github/workflows/test-functional-microstack.yaml | 9 +++++---- .github/workflows/test-unit.yaml | 5 ++++- ci/setup.sh | 4 ++++ .../tests/unit/test_migrate_field_of_science.py | 15 +++++++++++++++ test-requirements.txt | 1 + 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test-functional-microshift.yaml b/.github/workflows/test-functional-microshift.yaml index 718371ea..f3a8e32d 100644 --- a/.github/workflows/test-functional-microshift.yaml +++ b/.github/workflows/test-functional-microshift.yaml @@ -10,6 +10,7 @@ env: PYTHONWARNINGS: ignore KUBECONFIG: ${{ github.workspace }}/kubeconfig ACCT_MGT_VERSION: "cecbe131843e5033ab6f6fdce2b5a8af58d80f9d" + DB_URL: "postgres://postgres:postgres@localhost:5432/postgres" jobs: build: diff --git a/.github/workflows/test-functional-microstack.yaml b/.github/workflows/test-functional-microstack.yaml index d2ac51a6..f9ed469b 100644 --- a/.github/workflows/test-functional-microstack.yaml +++ b/.github/workflows/test-functional-microstack.yaml @@ -6,6 +6,9 @@ on: pull_request: branches: [ main ] +env: + DB_URL: "postgres://postgres:postgres@localhost:5432/postgres" + jobs: build: runs-on: ubuntu-22.04 @@ -18,11 +21,9 @@ jobs: with: python-version: 3.12 - - name: Install ColdFront and plugin + - name: Install dependancies, ColdFront and plugin run: | - python -m pip install --upgrade pip - pip install -r test-requirements.txt - pip install -e . + ./ci/setup.sh - name: Install and start Ceph RadosGW run: | diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 4e6f6b65..3298f383 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -6,6 +6,9 @@ on: pull_request: branches: [ main ] +env: + DB_URL: "postgres://postgres:postgres@localhost:5432/postgres" + jobs: build: runs-on: ubuntu-22.04 @@ -18,7 +21,7 @@ jobs: with: python-version: 3.12 - - name: Install ColdFront and plugin + - name: Install dependancies, ColdFront and plugin run: | ./ci/setup.sh diff --git a/ci/setup.sh b/ci/setup.sh index 76d242a5..6a5ff0c5 100755 --- a/ci/setup.sh +++ b/ci/setup.sh @@ -3,9 +3,13 @@ set -xe # If running on Github actions, don't create a virtualenv +# Else install postgres if [[ ! "${CI}" == "true" ]]; then virtualenv -p python3 /tmp/coldfront_venv source /tmp/coldfront_venv/bin/activate +else + sudo systemctl start postgresql.service + sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';" fi python -m pip install --upgrade pip diff --git a/src/coldfront_plugin_cloud/tests/unit/test_migrate_field_of_science.py b/src/coldfront_plugin_cloud/tests/unit/test_migrate_field_of_science.py index 8bc11f1a..7a7baabb 100644 --- a/src/coldfront_plugin_cloud/tests/unit/test_migrate_field_of_science.py +++ b/src/coldfront_plugin_cloud/tests/unit/test_migrate_field_of_science.py @@ -1,6 +1,8 @@ +import os import uuid import tempfile +from django.db import connection from django.core.management import call_command from coldfront.core.project.models import Project from coldfront.core.field_of_science.models import FieldOfScience @@ -9,6 +11,19 @@ class TestFixAllocation(base.TestBase): + def setUp(self) -> None: + """ + Because Coldfront manually sets the IDs of FieldOfScience (FOS) entries, this creates a mismatch + between the actual FOS IDs and the sequence that Postgres uses to auto-increment them + """ + super().setUp() + + if os.getenv("DB_URL"): + with connection.cursor() as cursor: + cursor.execute( + 'SELECT setval(pg_get_serial_sequence(\'field_of_science_fieldofscience\',\'id\'), coalesce(max("id"), 1), max("id") IS NOT null) FROM "field_of_science_fieldofscience";' + ) + def test_command_output(self): old_fos_1 = self.new_field_of_science() old_fos_2 = self.new_field_of_science() diff --git a/test-requirements.txt b/test-requirements.txt index 3d041edd..6161d07c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,3 +6,4 @@ python-keystoneclient python-novaclient python-neutronclient python-swiftclient +psycopg2 From 721a310324bdf3e2ace7346cd7b8e738200894ec Mon Sep 17 00:00:00 2001 From: Kristi Nikolla Date: Thu, 12 Feb 2026 11:17:56 -0500 Subject: [PATCH 2/2] Update .github/workflows/test-functional-microstack.yaml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/test-functional-microstack.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-functional-microstack.yaml b/.github/workflows/test-functional-microstack.yaml index f9ed469b..031b1e1d 100644 --- a/.github/workflows/test-functional-microstack.yaml +++ b/.github/workflows/test-functional-microstack.yaml @@ -21,7 +21,7 @@ jobs: with: python-version: 3.12 - - name: Install dependancies, ColdFront and plugin + - name: Install dependencies, ColdFront and plugin run: | ./ci/setup.sh