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