From c2cfb98f5a3e464595b0156370e9422c97543db0 Mon Sep 17 00:00:00 2001
From: Robbie Luijben <luijben@astron.nl>
Date: Tue, 21 Nov 2023 11:25:16 +0100
Subject: [PATCH] split up test config between local and CI

---
 .gitlab-ci.yml                            | 10 +++++-----
 README.md                                 | 10 +++++-----
 atdb/atdb/settings/{ci.py => test_ci.py}  |  8 ++++----
 atdb/atdb/settings/test_local.py          | 13 +++++++++++++
 atdb/docker/docker-compose-ci.yml         | 15 ---------------
 atdb/docker/docker-compose-test-local.yml | 15 +++++++++++++++
 atdb/test.bat                             |  2 +-
 7 files changed, 43 insertions(+), 30 deletions(-)
 rename atdb/atdb/settings/{ci.py => test_ci.py} (53%)
 create mode 100644 atdb/atdb/settings/test_local.py
 delete mode 100644 atdb/docker/docker-compose-ci.yml
 create mode 100644 atdb/docker/docker-compose-test-local.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f90aff83..6fc985be 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -25,14 +25,14 @@ test-code:
   services:
     - postgres:14.0
   variables:
-    POSTGRES_DB: atdb_ldv_ci
-    POSTGRES_USER: atdb_admin_ci
-    POSTGRES_PASSWORD: "atdb123_ci"
+    POSTGRES_DB: atdb_ldv_test_ci
+    POSTGRES_USER: atdb_admin_test_ci
+    POSTGRES_PASSWORD: "atdb123_test_ci"
   script:
     - cd atdb
     - pip install -r requirements/dev.txt
-    - python manage.py migrate --settings atdb.settings.ci
-    - python manage.py test --settings atdb.settings.ci
+    - python manage.py migrate --settings atdb.settings.test_ci
+    - python manage.py test --settings atdb.settings.test_ci
 
 
 # deploy to 'sdc-dev.astron.nl'
diff --git a/README.md b/README.md
index efc57cf9..6f3b237b 100644
--- a/README.md
+++ b/README.md
@@ -114,14 +114,14 @@ See the integration instructions in the [astronauth repo](https://git.astron.nl/
 
 ### Running tests
 
-To run tests, you can spin up a dedicated test database locally using the the provided `docker-compose-ci.yml` file. This test database will not interfere with your local development database. For example, you can run this command from the `atdb/docker` folder:
+To run tests, you can spin up a dedicated test database locally using the the provided `docker-compose-test-local.yml` file. This test database will not interfere with your local development database. For example, you can run this command from the `atdb/docker` folder:
 
-` docker compose -f .\docker-compose-ci.yml up -d`
+` docker compose -f .\docker-compose-test-local.yml up -d`
 
 After spinning up the database, you can execute the tests with the following command:
 
-`python manage.py test --settings atdb.settings.ci`
+`python manage.py test --settings atdb.settings.test_local`
 
-Dedicated settings for running the tests are provided in the `atdb/settings/ci.dev` file. For convenience, `test.bat` is provided to run the above command (Windows only).
+Dedicated settings for running the tests are provided in the `atdb/settings/test_local.dev` file. For convenience, `test.bat` is provided to run the above command (Windows only).
 
-Finally, these tests are also executed in the CI pipeline through the test stage in the `.gitlab-ci.yml` file.
\ No newline at end of file
+Finally, these tests are also executed in the CI pipeline through the test stage in the `.gitlab-ci.yml` file. For running the tests in the CI pipeline, the settings file `atdb/settings/test_ci.dev` is used.
\ No newline at end of file
diff --git a/atdb/atdb/settings/ci.py b/atdb/atdb/settings/test_ci.py
similarity index 53%
rename from atdb/atdb/settings/ci.py
rename to atdb/atdb/settings/test_ci.py
index 73a2d35a..b5bc3777 100644
--- a/atdb/atdb/settings/ci.py
+++ b/atdb/atdb/settings/test_ci.py
@@ -4,10 +4,10 @@ import os
 DATABASES = {
     'default': {
          'ENGINE': 'django.db.backends.postgresql_psycopg2',
-         'USER': 'atdb_admin_ci',
-         'PASSWORD': 'atdb123_ci',
-         'NAME': 'atdb_ldv_ci',
-         'HOST': 'localhost',
+         'USER': 'atdb_admin_test_ci',
+         'PASSWORD': 'atdb123_test_ci',
+         'NAME': 'atdb_ldv_test_ci',
+         'HOST': 'postgres',
          'PORT': '5432',
     },
 }
\ No newline at end of file
diff --git a/atdb/atdb/settings/test_local.py b/atdb/atdb/settings/test_local.py
new file mode 100644
index 00000000..6a70e4fa
--- /dev/null
+++ b/atdb/atdb/settings/test_local.py
@@ -0,0 +1,13 @@
+from atdb.settings.base import *
+import os
+
+DATABASES = {
+    'default': {
+         'ENGINE': 'django.db.backends.postgresql_psycopg2',
+         'USER': 'atdb_admin_test_local',
+         'PASSWORD': 'atdb123_test_local',
+         'NAME': 'atdb_ldv_test_local',
+         'HOST': 'localhost',
+         'PORT': '5555',
+    },
+}
\ No newline at end of file
diff --git a/atdb/docker/docker-compose-ci.yml b/atdb/docker/docker-compose-ci.yml
deleted file mode 100644
index 5774918f..00000000
--- a/atdb/docker/docker-compose-ci.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-version: '3.4'
-
-services:
-  atdb-ldv-db:
-    image: postgres:14
-    container_name: atdb-ldv-ci
-    expose:
-      - "5432"
-    ports:
-      - "5432:5432"
-    environment:
-      POSTGRES_PASSWORD: atdb123_ci
-      POSTGRES_USER: atdb_admin_ci
-      POSTGRES_DB: atdb_ldv_ci
-
diff --git a/atdb/docker/docker-compose-test-local.yml b/atdb/docker/docker-compose-test-local.yml
new file mode 100644
index 00000000..b3692434
--- /dev/null
+++ b/atdb/docker/docker-compose-test-local.yml
@@ -0,0 +1,15 @@
+version: '3.4'
+
+services:
+  atdb-ldv-db:
+    image: postgres:14
+    container_name: atdb-ldv-test-local
+    expose:
+      - "5432"
+    ports:
+      - "5555:5432"
+    environment:
+      POSTGRES_PASSWORD: atdb123_test_local
+      POSTGRES_USER: atdb_admin_test_local
+      POSTGRES_DB: atdb_ldv_test_local
+
diff --git a/atdb/test.bat b/atdb/test.bat
index 76519837..73190d46 100644
--- a/atdb/test.bat
+++ b/atdb/test.bat
@@ -1 +1 @@
-python manage.py test --settings atdb.settings.ci
+python manage.py test --settings atdb.settings.test_local
-- 
GitLab