Commit 2d2ec524 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

use postgres service to run tests

parent 508d85ca
......@@ -12,6 +12,15 @@ build:
stage: build
variables:
RUN_TEST: "1"
POSTGRES_HOST: "db-test"
STORAGE_SUFFIX: "-test"
POSTGRES_PASSWORD: "example"
DOCKER_HOST: tcp://localhost:2375
LC_COLLATE: POSIX
services:
- docker:dind
- name: postgres:10.1
alias: db-test
script:
- if [ $CI_COMMIT_REF_SLUG == "master" ]; then export RUN_TEST="1"; fi
# - export
......@@ -33,7 +42,10 @@ build:
./src/viralhostrange/
# Test if the build image is passing all the tests
- mkdir persistent_volume && chmod 777 persistent_volume
- if [ $RUN_TEST == "1" ]; then docker run -v $(pwd)/persistent_volume:/code/persistent_volume -e "USE_SQLITE_AS_DB=True" "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" test; fi
- if [ $RUN_TEST == "1" ]; then apk update && apk add postgresql-client; fi
- if [ $RUN_TEST == "1" ]; then until pg_isready -h ${POSTGRES_HOST}; do echo waiting; sleep 2; docker ps; done; fi
# - exit 1
- if [ $RUN_TEST == "1" ]; then docker run --network host -v $(pwd)/persistent_volume:/code/persistent_volume -e "STORAGE_SUFFIX=$STORAGE_SUFFIX" -e "POSTGRES_PASSWORD=$POSTGRES_PASSWORD" "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG" test; fi
- if [ $RUN_TEST == "1" ]; then mv persistent_volume/htmlcov ./htmlcov; fi
# Tests have been passed, so pushing
# if we are on master branch, tag the build with latest and push it
......
......@@ -6,6 +6,7 @@ metadata:
branch: branch${STORAGE_SUFFIX}
data:
POSTGRES_PASSWORD: "$POSTGRES_PASSWORD"
LC_COLLATE: "POSIX"
ALLOWED_HOSTS: "$PUBLIC_URL"
DEBUG: "$DEBUG"
STORAGE_SUFFIX: "$STORAGE_SUFFIX"
......
......@@ -2,4 +2,8 @@
docker build . -t test
docker run -v $(pwd)/persistent_volume:/code/persistent_volume -e "USE_SQLITE_AS_DB=True" -e "ALLOWED_HOSTS=localhost" -e "SECRET_KEY=*" -e "DEBUG=True" -e "STATIC_URL=/static" -e "PROJECT_NAME=viralhostrange" -p 8086:8086 test
```
```
docker run --name db-test_db -e POSTGRES_PASSWORD=eee -e LC_COLLATE=POSIX -p 5432:5432 -d postgres:10.1
```
\ No newline at end of file
from django.core.cache import cache
from django.db import OperationalError
from django.db import OperationalError, ProgrammingError
class LiveSettings(object):
......@@ -8,7 +8,7 @@ class LiveSettings(object):
from live_settings.models import LiveSettings
LiveSettings.objects.update_or_create(key=key, defaults=dict(value=value))
except OperationalError:
except (ProgrammingError, OperationalError):
return super().__setattr__(key, value)
def __getattribute__(self, key):
......@@ -21,7 +21,7 @@ class LiveSettings(object):
LiveSettings.objects.values_list("key", "value")
)
cache.set("live_settings_dict", live_settings_dict)
except OperationalError:
except (ProgrammingError, OperationalError):
return super().__getattribute__(key)
return live_settings_dict.get(key, None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment