-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests only set up database once now, fixes #96
- Loading branch information
Showing
2 changed files
with
39 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
# openpoiservice/server/tests/base.py | ||
|
||
from flask_testing import TestCase | ||
from pathlib import Path | ||
from openpoiservice import db, create_app, config_map | ||
from openpoiservice.utils import parser | ||
import unittest | ||
import os | ||
from pathlib import Path | ||
|
||
app = create_app('testing') | ||
from openpoiservice import db, create_app | ||
from openpoiservice.utils import parser | ||
from openpoiservice.logger import logger | ||
|
||
this_path = Path(os.path.dirname(__file__)) | ||
|
||
class BaseTestCase(TestCase): | ||
class BaseTestCase(unittest.TestCase): | ||
|
||
def create_app(self): | ||
app.config.from_object(config_map['testing']) | ||
@classmethod | ||
def setUpClass(cls): | ||
app = create_app('testing') | ||
app.app_context().push() | ||
cls.app = app | ||
|
||
return app | ||
cls.db = db | ||
cls.db.app = cls.app | ||
|
||
def setUp(self): | ||
db.create_all() | ||
logger.info(f"""The following database settings are active: | ||
\tHost: {cls.db.engine.url.host}:{cls.db.engine.url.port} | ||
\tDatabase: {cls.db.engine.url.database} | ||
\tUser: {cls.db.engine.url.username}""") | ||
|
||
test_file = Path(os.path.join('tests', 'data', 'bremen-tests.osm.pbf')) | ||
cls.db.create_all() | ||
logger.info("Created tables:\n\t{}".format("\n\t".join(cls.db.metadata.tables.keys()))) | ||
|
||
# Import test data | ||
test_file = Path(os.path.join(this_path, 'data', 'bremen-tests.osm.pbf')) | ||
parser.parse_import(test_file) | ||
super().setUpClass() | ||
|
||
def tearDown(self): | ||
db.session.remove() | ||
@classmethod | ||
def tearDownClass(cls): | ||
super().tearDownClass() | ||
db.drop_all() | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.client = self.app.test_client() | ||
self.app_context = self.app.app_context() | ||
self.app_context.push() | ||
|
||
def tearDown(self): | ||
super().tearDown() | ||
self.app_context.pop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters