source: src/mapservice/codegen/templates/__init__test.mustache@ 75f09e4

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

Fixed spatial lite testing

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[3a89adb]1import logging
2
3import connexion
[be25db1]4from flask_cors import CORS
[3a89adb]5from flask_testing import TestCase
[fc99a86]6from sqlalchemy.event import listen
[3a89adb]7
8from {{packageName}}.encoder import JSONEncoder
[be25db1]9from {{packageName}}.server_impl.database.Model import db, db_test_setup
[3a89adb]10
[fc99a86]11def load_spatialite(dbapi_conn, connection_record):
12 print("enable spatial lite extension")
13 # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html
14 dbapi_conn.enable_load_extension(True)
15 dbapi_conn.load_extension('/usr/local/lib64/mod_spatialite')
16
[3a89adb]17class BaseTestCase(TestCase):
[be25db1]18 def create_app(self):
19 logging.getLogger('connexion.operation').setLevel('ERROR')
20 app = connexion.App(__name__, specification_dir='../openapi/')
21 application = app.app
22 CORS(application)
23 application.json_encoder = JSONEncoder
24 app.add_api('openapi.yaml')
[3a89adb]25
[be25db1]26 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
27 db.init_app(application)
28 application.app_context().push()
29
30 return application
31
32 def setUp(self):
[fc99a86]33 listen(db.engine, 'connect', load_spatialite)
[be25db1]34 db.drop_all()
35 db_test_setup()
36
37 def tearDown(self):
38 db.session.remove()
39 db.drop_all()
Note: See TracBrowser for help on using the repository browser.