Commit 2d6b3bed authored by Alain Takoudjou's avatar Alain Takoudjou

remove app, db from web to prevent using a different app_context in tests

parent 6e3bb8e5
......@@ -23,3 +23,15 @@ except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
# Use default value so SQLALCHEMY will not warn because there is not db_uri
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///ca.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
from caucase import web, storage
\ No newline at end of file
......@@ -22,7 +22,7 @@ import uuid
import hashlib
from datetime import datetime, timedelta
from OpenSSL import crypto
from caucase.web import db
from caucase import db
from caucase import utils
from caucase.exceptions import (NoStorage, NotFound, Found)
from flask_user import UserMixin
......
......@@ -23,7 +23,7 @@ import tempfile
import unittest
import json
from datetime import datetime
from caucase.web import app, db
from caucase import app, db
from OpenSSL import crypto, SSL
from caucase.exceptions import (NoStorage, NotFound, Found, BadSignature,
BadCertificateSigningRequest,
......
......@@ -27,6 +27,7 @@ from caucase.web import parseArguments, configure_flask
from OpenSSL import crypto, SSL
from caucase.exceptions import (NoStorage, NotFound, Found)
from caucase import utils
from caucase import db, app
from flask_testing import TestCase
from flask import url_for
......@@ -37,14 +38,12 @@ class CertificateAuthorityWebTest(TestCase):
configure_flask(parseArguments(['--ca-dir', self.ca_dir, '-s', '/CN=CA Auth Test/emailAddress=xx@example.com']))
def tearDown(self):
from caucase.web import db
db.session.remove()
db.drop_all()
if os.path.exists(self.ca_dir):
shutil.rmtree(self.ca_dir)
def create_app(self):
from caucase.web import app
app.config['TESTING'] = True
app.config['LIVESERVER_PORT'] = 0
return app
......
......@@ -23,7 +23,8 @@ import tempfile
import unittest
import json
from datetime import datetime, timedelta
from caucase.web import app, db
from caucase import app, db
from caucase.storage import Storage, Config
from OpenSSL import crypto, SSL
from caucase.exceptions import (NoStorage, NotFound, Found)
from sqlite3 import IntegrityError
......@@ -45,12 +46,11 @@ class StorageTest(unittest.TestCase):
TESTING=True,
SQLALCHEMY_DATABASE_URI='sqlite:///%s' % self.db_file
)
from caucase.storage import Storage
self._storage = Storage(db)
self._storage = Storage(db)
def setConfig(self, key, value):
entry = self._storage._getConfig(key)
from caucase.storage import Config
if not entry:
entry = Config(key=key, value='%s' % value)
db.session.add(entry)
......
......@@ -23,9 +23,8 @@ import argparse
import traceback
import json
import flask
from flask import (Flask, session, request, redirect, url_for, render_template,
jsonify, session, abort, send_file, flash, g, Response)
from flask_sqlalchemy import SQLAlchemy
from flask import (session, request, redirect, url_for, render_template,
jsonify, abort, send_file, flash, g, Response)
from flask_user import UserManager, SQLAlchemyAdapter
from wtforms import StringField, SubmitField, validators
from flask_wtf import FlaskForm
......@@ -40,13 +39,7 @@ from caucase.exceptions import (NoStorage, NotFound, Found, BadSignature,
ExpiredCertificate)
from functools import wraps
from caucase import utils
app = Flask(__name__)
# Use default value so SQLALCHEMY will not warn because there is not db_uri
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///ca.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
from caucase import app, db
class DisabledStringField(StringField):
def __call__(self, *args, **kwargs):
......
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