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

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

To find the template files, when started per installed package and per module from src-gen

  • Folder for templates is now set (in the descending priority)
    • per Config option TEMPLATE_FOLDER
    • per template_folder optional argument to setup_app(). The option is set by main.py (see mustache)

For tests the template_folder is set by init.py from test folder (s. inittest.mustache)

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[3a89adb]1import logging
2
[be66b78]3import flask
[3a89adb]4import connexion
[be25db1]5from flask_cors import CORS
[3a89adb]6from flask_testing import TestCase
[ae2ff15]7from flask_mail import Mail
[fc99a86]8from sqlalchemy.event import listen
[be66b78]9from celery import Celery
[ae2ff15]10import tempfile
11import os
12from PIL import Image
13import shutil
[3a89adb]14
15from {{packageName}}.encoder import JSONEncoder
[5ec7c42]16from {{packageName}}.server_impl.database.Model import db, db_setup, load_spatialite
[ae2ff15]17from . import db_test_setup
[fc99a86]18
[3a89adb]19class BaseTestCase(TestCase):
[be25db1]20 def create_app(self):
21 logging.getLogger('connexion.operation').setLevel('ERROR')
22 app = connexion.App(__name__, specification_dir='../openapi/')
23 application = app.app
24 CORS(application)
[ae2ff15]25 mail = Mail()
[be25db1]26 application.json_encoder = JSONEncoder
27 app.add_api('openapi.yaml')
[3a89adb]28
[be25db1]29 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
[5c9c247]30 application.template_folder = os.path.join(os.path.dirname(__file__), '../templates')
[be66b78]31 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
32 celery.config_from_object(application.config)
[ae2ff15]33 mail.init_app(application)
[be25db1]34 db.init_app(application)
35 application.app_context().push()
36
[ae2ff15]37 self._create_test_tile(application)
38
[be25db1]39 return application
40
41 def setUp(self):
[fc99a86]42 listen(db.engine, 'connect', load_spatialite)
[be25db1]43 db.drop_all()
[5ec7c42]44 # create the tables whether the database already exists or not
[ae2ff15]45 db_setup(True)
46 self.db_content = db_test_setup.DatabaseContent()
47 self.db_content.setup()
[be25db1]48
49 def tearDown(self):
50 db.session.remove()
51 db.drop_all()
[ae2ff15]52 shutil.rmtree(self.tiles_cache)
53
54 def _create_test_tile(self, application):
55 self.tiles_cache = tempfile.mkdtemp(prefix='gnuboat-tests')
56 application.config['TILES_CACHE_PATH'] = self.tiles_cache
57
58 tile_path = os.path.join(self.tiles_cache, '100_100/256/15/17298/')
59 os.makedirs(tile_path)
60 img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
61 img.save(os.path.join(tile_path, "21435.png"), "PNG")
62
63 def check_key(self, key, value, data):
64 assert key in data, "{} not in data {}".format(key, data)
65 assert data[key] == value, "{} = {}".format(value, data[key])
Note: See TracBrowser for help on using the repository browser.