]> git.aero2k.de Git - sirius.git/commitdiff
Trying to get tests running cleanly with docker test instances of databases, under...
authorJoshua May <notjosh@gmail.com>
Sun, 1 Sep 2019 21:04:02 +0000 (14:04 -0700)
committerJoshua May <notjosh@gmail.com>
Sun, 1 Sep 2019 21:04:02 +0000 (14:04 -0700)
Makefile [new file with mode: 0644]
docker-compose.db.yml [new file with mode: 0644]
docker-compose.development.yml
docker-compose.test.yml [new file with mode: 0644]
docker-compose.yml
manage.py
requirements.txt
sirius/config.py
sirius/testing/base.py
sirius/web/test_printing.py

diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..33eee6b
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
+run-development:
+       docker-compose -f docker-compose.yml -f docker-compose.db.yml -f docker-compose.development.yml up
+
+run-test:
+       docker rm -v sirius-database-test || true
+       docker-compose -f docker-compose.yml -f docker-compose.test.yml up
\ No newline at end of file
diff --git a/docker-compose.db.yml b/docker-compose.db.yml
new file mode 100644 (file)
index 0000000..461fd76
--- /dev/null
@@ -0,0 +1,16 @@
+version: "3"
+
+services:
+  sirius:
+    depends_on:
+      - sirius-database
+    environment:
+      - DATABASE_URL=postgresql://postgres:plop@sirius-database/sirius
+
+  sirius-database:
+    image: postgres
+    healthcheck:
+      test: "exit 0"
+    environment:
+      - POSTGRES_DB=sirius
+      - POSTGRES_PASSWORD=plop
index a3e7677d7c9faebc072856256bffdeb3d01a4af3..2b4eb8c3ff182029a07e774e1b1b1105a0394007 100644 (file)
@@ -4,22 +4,11 @@ services:
   sirius:
     ports:
       - 5000:5000
-    depends_on:
-      - sirius-database
-    command:
-      [
-        "bin/wait-for-it.sh",
-        "sirius-database:5432",
-        "--",
-        "bin/docker-entrypoint.sh",
-      ]
     environment:
       - VIRTUAL_HOST=sirius.localhost
+      - DATABASE_URL=postgresql://postgres:plop@sirius-database/sirius-dev
 
   sirius-database:
-    image: postgres
-    healthcheck:
-      test: "exit 0"
     ports:
       - "32770:5432"
     environment:
diff --git a/docker-compose.test.yml b/docker-compose.test.yml
new file mode 100644 (file)
index 0000000..15e4baf
--- /dev/null
@@ -0,0 +1,17 @@
+version: "3"
+
+services:
+  sirius:
+    depends_on:
+      - sirius-database-test
+    environment:
+      - DATABASE_URL=postgresql://postgres:plop@sirius-database/sirius-test
+
+  sirius-database-test:
+    container_name: sirius-database-test
+    image: postgres
+    healthcheck:
+      test: "exit 0"
+    environment:
+      - POSTGRES_DB=sirius-test
+      - POSTGRES_PASSWORD=plop
index 1e8cc6a3ed03a58bba64c869de710713b3deafa1..2c4133d3fd75e3b10168bb6d4a34df8d1b4c5133 100644 (file)
@@ -5,9 +5,15 @@ services:
     build:
       context: ./
       dockerfile: ./Dockerfile
-    env_file:
-      - .env
-    command: "./manage.py db upgrade"
+    depends_on:
+      - sirius-web
+    command:
+      [
+        "bin/wait-for-it.sh",
+        "sirius-database:5432",
+        "--",
+        "bin/docker-entrypoint.sh",
+      ]
     environment:
       - OPENSSL_CONF=/etc/ssl/
 
@@ -19,5 +25,3 @@ services:
     volumes:
       - /var/run/docker.sock:/tmp/docker.sock:ro
       - ./certs:/etc/nginx/certs
-    depends_on:
-      - sirius
index 6aff4cf985428123a12b24f113f7ce7a1db6b234..576e0f25aea8463e49b0befec6082a3a01d7ffd9 100755 (executable)
--- a/manage.py
+++ b/manage.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python2.7
+#!/usr/bin/env python3
 
 import os, sys
 import re
index 04801b8ce5a0d31f473e7bbaeb8b100df8e6068f..2bd0acf973d747ac4a1c90cb1e764b64331a4b3f 100755 (executable)
@@ -1,10 +1,10 @@
-Flask==0.10.1
+Flask==0.12.4
 Flask-Bootstrap==3.2.0.2
 Flask-Cors==3.0.7
 Flask-Login==0.2.11
 Flask-Migrate==1.2.0
 git+https://github.com/mitsuhiko/flask-oauth@af6432621a9add5e55b0d7638e1380f66f3d4ed0#egg=Flask-OAuth
-Flask-SQLAlchemy==2.0
+Flask-SQLAlchemy==2.4.0
 Flask-Script==2.0.5
 Flask-Sockets==0.1
 Flask-Testing==0.4.2
@@ -13,7 +13,7 @@ Jinja2==2.7.3
 Mako==1.0.0
 MarkupSafe==0.23
 pillow==2.9.0
-SQLAlchemy==0.9.7
+SQLAlchemy==1.3.8
 WTForms==2.0.1
 Werkzeug==0.9.6
 alembic==0.6.7
index 1036c979626ebf88ab48a1d404569ca1a6b08aec..99ad23d0cc8cde6da307575a38d8b971a4f275c5 100755 (executable)
@@ -5,6 +5,7 @@ basedir = os.path.abspath(os.path.dirname(__file__))
 class Config:
     SECRET_KEY = os.environ.get('SECRET_KEY') or 'this is the lp2 secret'
     SQLALCHEMY_COMMIT_ON_TEARDOWN = True
+    SQLALCHEMY_TRACK_MODIFICATIONS = False
     # printer not seen for 60 seconds: Mark offline.
     PRINTER_OFFLINE_CUTOFF_SECONDS = 60
 
@@ -14,14 +15,15 @@ class Config:
 
 class TestConfig(Config):
     DEBUG = False
-    SQLALCHEMY_DATABASE_URI = 'sqlite://'
+    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
+        'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
     TESTING = True
     WTF_CSRF_ENABLED = False
     LOGIN_DISABLED = False
 
 class DevelopmentConfig(Config):
     DEBUG = True
-    SQLALCHEMY_DATABASE_URI = os.environ.get('DEV_DATABASE_URL') or \
+    SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \
         'sqlite:///' + os.path.join(basedir, 'data-dev.sqlite')
 
 class ProductionConfig(Config):
index e77e8cc6313f9927d7b0aaebea92ee54f58f9abf..f2cf7939de514a1ab0181453e31b4bdc3cf246ae 100644 (file)
@@ -18,6 +18,7 @@ class Base(testing.TestCase):
     def setUp(self):
         testing.TestCase.setUp(self)
         db.create_all()
+        db.session.begin_nested()
         self.testuser = user.User(
             username="testuser",
             twitter_oauth=user.TwitterOAuth(
@@ -28,9 +29,9 @@ class Base(testing.TestCase):
             )
         )
         db.session.add(self.testuser)
-        db.session.commit()
 
     def tearDown(self):
+        db.session.rollback()
         db.session.remove()
         db.drop_all()
 
index ccbbfc47f15a28f8431966182fe5cb3b8a368d25..748e6301cc9a4d0deb343477217ebf1bed2d187d 100644 (file)
@@ -27,7 +27,7 @@ class TestPrinting(base.Base):
     def test_print_ok(self):
         r = self.client.post(self.get_print_url(), data=dict(
             target_printer=self.printer.id, message='hello'))
-        print r.headers
+        print(r.headers)
         self.assertRedirects(r, '/printer/1')
 
     def test_print_wrong_printer(self):