source: src/mapservice/codegen/templates/__init__test.mustache@ 5c9c247

debian/bullseye
Last change on this file since 5c9c247 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
Line 
1import logging
2
3import flask
4import connexion
5from flask_cors import CORS
6from flask_testing import TestCase
7from flask_mail import Mail
8from sqlalchemy.event import listen
9from celery import Celery
10import tempfile
11import os
12from PIL import Image
13import shutil
14
15from {{packageName}}.encoder import JSONEncoder
16from {{packageName}}.server_impl.database.Model import db, db_setup, load_spatialite
17from . import db_test_setup
18
19class BaseTestCase(TestCase):
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)
25 mail = Mail()
26 application.json_encoder = JSONEncoder
27 app.add_api('openapi.yaml')
28
29 application.config.from_object('{{packageName}}.server_impl.Config.TestingConfig')
30 application.template_folder = os.path.join(os.path.dirname(__file__), '../templates')
31 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
32 celery.config_from_object(application.config)
33 mail.init_app(application)
34 db.init_app(application)
35 application.app_context().push()
36
37 self._create_test_tile(application)
38
39 return application
40
41 def setUp(self):
42 listen(db.engine, 'connect', load_spatialite)
43 db.drop_all()
44 # create the tables whether the database already exists or not
45 db_setup(True)
46 self.db_content = db_test_setup.DatabaseContent()
47 self.db_content.setup()
48
49 def tearDown(self):
50 db.session.remove()
51 db.drop_all()
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.