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

debian/bullseye
Last change on this file since ce59b61 was be66b78, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added Celery to the testing initialisation
    • Ommitting log creation for demo puproses, if no CELERY_BROKER is set, because the tasks.delay() call never times out, if no broker is running
  • Property mode set to 100644
File size: 1.2 KB
Line 
1import logging
2
3import flask
4import connexion
5from flask_cors import CORS
6from flask_testing import TestCase
7from sqlalchemy.event import listen
8from celery import Celery
9
10from {{packageName}}.encoder import JSONEncoder
11from {{packageName}}.server_impl.database.Model import db, db_setup, load_spatialite
12from {{packageName}}.server_impl.demo import DbSetup as demoDbSetup
13
14class BaseTestCase(TestCase):
15 def create_app(self):
16 logging.getLogger('connexion.operation').setLevel('ERROR')
17 app = connexion.App(__name__, specification_dir='../openapi/')
18 application = app.app
19 CORS(application)
20 application.json_encoder = JSONEncoder
21 app.add_api('openapi.yaml')
22
23 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
24 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
25 celery.config_from_object(application.config)
26 db.init_app(application)
27 application.app_context().push()
28
29 return application
30
31 def setUp(self):
32 listen(db.engine, 'connect', load_spatialite)
33 db.drop_all()
34 # create the tables whether the database already exists or not
35 db_setup(False)
36 demoDbSetup.setup()
37
38 def tearDown(self):
39 db.session.remove()
40 db.drop_all()
Note: See TracBrowser for help on using the repository browser.