Skip to content

Commit 1a93876

Browse files
authored
Merge pull request #286 from QuanMPhm/254/postgres
Use postgres for CI run_unit_tests
2 parents aa758db + 721a310 commit 1a93876

File tree

6 files changed

+30
-5
lines changed

6 files changed

+30
-5
lines changed

.github/workflows/test-functional-microshift.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ env:
1010
PYTHONWARNINGS: ignore
1111
KUBECONFIG: ${{ github.workspace }}/kubeconfig
1212
ACCT_MGT_VERSION: "cecbe131843e5033ab6f6fdce2b5a8af58d80f9d"
13+
DB_URL: "postgres://postgres:postgres@localhost:5432/postgres"
1314

1415
jobs:
1516
build:

.github/workflows/test-functional-microstack.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
DB_URL: "postgres://postgres:postgres@localhost:5432/postgres"
11+
912
jobs:
1013
build:
1114
runs-on: ubuntu-22.04
@@ -18,11 +21,9 @@ jobs:
1821
with:
1922
python-version: 3.12
2023

21-
- name: Install ColdFront and plugin
24+
- name: Install dependencies, ColdFront and plugin
2225
run: |
23-
python -m pip install --upgrade pip
24-
pip install -r test-requirements.txt
25-
pip install -e .
26+
./ci/setup.sh
2627
2728
- name: Install and start Ceph RadosGW
2829
run: |

.github/workflows/test-unit.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
pull_request:
77
branches: [ main ]
88

9+
env:
10+
DB_URL: "postgres://postgres:postgres@localhost:5432/postgres"
11+
912
jobs:
1013
build:
1114
runs-on: ubuntu-22.04
@@ -18,7 +21,7 @@ jobs:
1821
with:
1922
python-version: 3.12
2023

21-
- name: Install ColdFront and plugin
24+
- name: Install dependancies, ColdFront and plugin
2225
run: |
2326
./ci/setup.sh
2427

ci/setup.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
set -xe
44

55
# If running on Github actions, don't create a virtualenv
6+
# Else install postgres
67
if [[ ! "${CI}" == "true" ]]; then
78
virtualenv -p python3 /tmp/coldfront_venv
89
source /tmp/coldfront_venv/bin/activate
10+
else
11+
sudo systemctl start postgresql.service
12+
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres';"
913
fi
1014

1115
python -m pip install --upgrade pip

src/coldfront_plugin_cloud/tests/unit/test_migrate_field_of_science.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import os
12
import uuid
23
import tempfile
34

5+
from django.db import connection
46
from django.core.management import call_command
57
from coldfront.core.project.models import Project
68
from coldfront.core.field_of_science.models import FieldOfScience
@@ -9,6 +11,19 @@
911

1012

1113
class TestFixAllocation(base.TestBase):
14+
def setUp(self) -> None:
15+
"""
16+
Because Coldfront manually sets the IDs of FieldOfScience (FOS) entries, this creates a mismatch
17+
between the actual FOS IDs and the sequence that Postgres uses to auto-increment them
18+
"""
19+
super().setUp()
20+
21+
if os.getenv("DB_URL"):
22+
with connection.cursor() as cursor:
23+
cursor.execute(
24+
'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";'
25+
)
26+
1227
def test_command_output(self):
1328
old_fos_1 = self.new_field_of_science()
1429
old_fos_2 = self.new_field_of_science()

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ python-keystoneclient
66
python-novaclient
77
python-neutronclient
88
python-swiftclient
9+
psycopg2

0 commit comments

Comments
 (0)