From 99f33dd392145b37871842999598e8db654166d3 Mon Sep 17 00:00:00 2001
From: Eliot Berriot <contact@eliotberriot.com>
Date: Mon, 12 Mar 2018 23:07:08 +0100
Subject: [PATCH] Make api docker image able to run tests

---
 api/compose/django/dev-entrypoint.sh |  7 +++++++
 api/config/settings/test.py          |  5 +----
 api/docker/Dockerfile.test           |  1 +
 api/test.yml                         | 18 ------------------
 4 files changed, 9 insertions(+), 22 deletions(-)
 create mode 100755 api/compose/django/dev-entrypoint.sh
 delete mode 100644 api/test.yml

diff --git a/api/compose/django/dev-entrypoint.sh b/api/compose/django/dev-entrypoint.sh
new file mode 100755
index 00000000..416207b4
--- /dev/null
+++ b/api/compose/django/dev-entrypoint.sh
@@ -0,0 +1,7 @@
+#!/bin/bash
+set -e
+if [ $1 = "pytest" ]; then
+    # let pytest.ini handle it
+    unset DJANGO_SETTINGS_MODULE
+fi
+exec "$@"
diff --git a/api/config/settings/test.py b/api/config/settings/test.py
index a0b6b250..aff29c65 100644
--- a/api/config/settings/test.py
+++ b/api/config/settings/test.py
@@ -19,10 +19,6 @@ CACHES = {
 
 CELERY_BROKER_URL = 'memory://'
 
-# TESTING
-# ------------------------------------------------------------------------------
-TEST_RUNNER = 'django.test.runner.DiscoverRunner'
-
 ########## CELERY
 # In development, all tasks will be executed locally by blocking until the task returns
 CELERY_TASK_ALWAYS_EAGER = True
@@ -30,3 +26,4 @@ CELERY_TASK_ALWAYS_EAGER = True
 
 # Your local stuff: Below this line define 3rd party library settings
 API_AUTHENTICATION_REQUIRED = False
+CACHEOPS_ENABLED = False
diff --git a/api/docker/Dockerfile.test b/api/docker/Dockerfile.test
index 00638e9d..0990efa5 100644
--- a/api/docker/Dockerfile.test
+++ b/api/docker/Dockerfile.test
@@ -23,3 +23,4 @@ RUN pip install -r /requirements/test.txt
 
 COPY . /app
 WORKDIR /app
+ENTRYPOINT ["compose/django/dev-entrypoint.sh"]
diff --git a/api/test.yml b/api/test.yml
deleted file mode 100644
index 85a3a37f..00000000
--- a/api/test.yml
+++ /dev/null
@@ -1,18 +0,0 @@
-version: '2'
-services:
-  test:
-    build:
-      dockerfile: docker/Dockerfile.test
-      context: .
-    command: pytest
-    depends_on:
-      - postgres
-    volumes:
-      - .:/app
-    environment:
-      - "DJANGO_ALLOWED_HOSTS=localhost"
-      - "DATABASE_URL=postgresql://postgres@postgres/postgres"
-      - "FUNKWHALE_URL=https://funkwhale.test"
-      - "CACHEOPS_ENABLED=False"
-  postgres:
-    image: postgres
-- 
GitLab