Setup app for testing
diff --git a/.gitignore b/.gitignore
index 5a2be01..085713c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@
# Unit test / coverage reports
.coverage
+cover
.tox
nosetests.xml
diff --git a/gstack/__init__.py b/gstack/__init__.py
index 2627d2b..1a8b400 100644
--- a/gstack/__init__.py
+++ b/gstack/__init__.py
@@ -36,12 +36,16 @@
return config_file
-def configure_app():
- config_file = _load_config_file()
- app.config.from_pyfile(config_file)
+def configure_app(settings=None):
app.config['DATA'] = os.path.abspath(os.path.dirname(__file__)) + '/data'
- app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
- os.path.join(app.config['DATA'], 'app.db')
+
+ if settings:
+ app.config.from_object(settings)
+ else:
+ config_file = _load_config_file()
+ app.config.from_pyfile(config_file)
+ app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
+ os.path.join(app.config['DATA'], 'app.db')
app = Flask(__name__)
diff --git a/tests/__init__.py b/tests/__init__.py
index 20dd554..426ca04 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,8 +1,29 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
from unittest import TestCase
+from gstack import app, configure_app
+from . import settings
+from .utils import FlaskTestCaseMixin
+
class GStackTestCase(TestCase):
pass
class GStackAppTestCase(FlaskTestCaseMixin, GStackTestCase):
+ def _configure_app(self):
+ configure_app(settings=settings)
+
+ def setUp(self):
+ super(GStackTestCase, self).setUp()
+ self._configure_app()
+ self.app = app
+ self.client = self.app.test_client()
+ self.app_context = self.app.app_context()
+ self.app_context.push()
+
+ def tearDown(self):
+ super(GStackTestCase, self).tearDown()
+ self.app_context.pop()
diff --git a/tests/sample_tests.py b/tests/sample_tests.py
new file mode 100644
index 0000000..8756580
--- /dev/null
+++ b/tests/sample_tests.py
@@ -0,0 +1,9 @@
+#!/usr/bin/env python
+# encoding: utf-8
+
+from . import GStackAppTestCase
+
+class SampleTestCase(GStackAppTestCase):
+
+ def test_sample(self):
+ pass
\ No newline at end of file