From 31cbe4bcac1f9ccdba92b62795155460560071a8 Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Thu, 26 Sep 2024 15:48:25 +0200
Subject: [PATCH] move redcap test instance settings to environment variables
 by default (they can still be overriden in local_settings as well)

---
 .gitlab-ci.yml          |  2 ++
 CHANGELOG               |  1 +
 requirements.txt        |  2 --
 smash/smash/settings.py | 10 ++++++++--
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2310f11f..64bc9f8e 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -44,6 +44,7 @@ test_postgres:
          - postgres:latest
     script:
          - cp "local_settings_ci.py" "smash/smash/local_settings.py"
+         - pip install "psycopg2==2.9.9"
          - cd smash
          - coverage run --source web manage.py test -v3
          - coverage report -m --omit="*/test*,*/migrations*,*debug_utils*"
@@ -54,6 +55,7 @@ test_mariadb:
          - mariadb:10.6-ubi
     script:
          - cp "local_settings_ci_mariadb.py" "smash/smash/local_settings.py"
+         - pip install "mysqlclient==2.2.4"
          - cd smash
          - sleep 10
          - coverage run --source web manage.py test --noinput -v3
diff --git a/CHANGELOG b/CHANGELOG
index 79646dd2..21cb55fd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 smasch (1.4.5-1) stable; urgency=medium
   * added support for mariadb
+  * allow overriding the redcap test instance in settings.
 
   -- Carlos Vega <carlos.vega@lih.lu> Wed, 31 Jul 2024 10:11:00 +0200
 
diff --git a/requirements.txt b/requirements.txt
index 2b48025a..b575d0f3 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -31,7 +31,6 @@ luhn==0.2.0
 lxml==4.9.3
 matplotlib==3.8.1
 mockito==1.4.0
-mysqlclient==2.2.4
 nexmo==2.5.2
 numpy==1.26.1
 pandas==2.1.2
@@ -39,7 +38,6 @@ packaging==23.2
 django-datatables-view==1.20.0
 phonenumberslite==8.13.24
 Pillow==10.1.0
-psycopg2==2.9.9
 pycparser==2.21
 pyexcel==0.7.0
 pyexcel-io==0.6.6
diff --git a/smash/smash/settings.py b/smash/smash/settings.py
index 5d3a28ae..12e6fc6b 100644
--- a/smash/smash/settings.py
+++ b/smash/smash/settings.py
@@ -11,12 +11,15 @@ https://docs.djangoproject.com/en/1.10/ref/settings/
 """
 
 import functools
+import logging
 import os
 import ldap
 from django_auth_ldap.config import LDAPSearch
 
 from django.contrib.staticfiles import storage
 
+logger = logging.getLogger(__name__)
+
 # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
@@ -25,8 +28,11 @@ PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
 
 # To run the unit tests we need a redcap instance.
 # UL
-REDCAP_TEST_API_TOKEN = "5DC21D45E3A2E068659F11046EA88734"
-REDCAP_TEST_URL = "https://luxparktest.lcsb.uni.lu/redcap/"
+REDCAP_TEST_API_TOKEN = os.environ.get('REDCAP_TEST_API_TOKEN', None)
+REDCAP_TEST_URL = os.environ.get('REDCAP_TEST_URL', None)
+
+if REDCAP_TEST_API_TOKEN is None or REDCAP_TEST_URL is None:
+    logging.warning('Environment variables REDCAP_TEST_API_TOKEN or REDCAP_TEST_URL does not exist. Unit tests for redcap will fail without them having proper values.')
 
 COPYRIGHT_NOTE = "2024 Bioinformatics Core, Luxembourg Centre for Systems Biomedicine"
 
-- 
GitLab