source: src/mapservice/codegen/templates/__init__test.mustache@ cc107a8

debian/bullseye
Last change on this file since cc107a8 was 5ec7c42, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago

Improved database setup

  • Property mode set to 100644
File size: 1.0 KB
Line 
1import logging
2
3import connexion
4from flask_cors import CORS
5from flask_testing import TestCase
6from sqlalchemy.event import listen
7
8from {{packageName}}.encoder import JSONEncoder
9from {{packageName}}.server_impl.database.Model import db, db_setup, load_spatialite
10from {{packageName}}.server_impl.demo import DbSetup as demoDbSetup
11
12class BaseTestCase(TestCase):
13 def create_app(self):
14 logging.getLogger('connexion.operation').setLevel('ERROR')
15 app = connexion.App(__name__, specification_dir='../openapi/')
16 application = app.app
17 CORS(application)
18 application.json_encoder = JSONEncoder
19 app.add_api('openapi.yaml')
20
21 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
22 db.init_app(application)
23 application.app_context().push()
24
25 return application
26
27 def setUp(self):
28 listen(db.engine, 'connect', load_spatialite)
29 db.drop_all()
30 # create the tables whether the database already exists or not
31 db_setup(False)
32 demoDbSetup.setup()
33
34 def tearDown(self):
35 db.session.remove()
36 db.drop_all()
Note: See TracBrowser for help on using the repository browser.