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

debian/bullseye
Last change on this file since ae2ff15 was ae2ff15, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
  • Property mode set to 100644
File size: 1.9 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')
[be66b78]30 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
31 celery.config_from_object(application.config)
[ae2ff15]32 mail.init_app(application)
[be25db1]33 db.init_app(application)
34 application.app_context().push()
35
[ae2ff15]36 self._create_test_tile(application)
37
[be25db1]38 return application
39
40 def setUp(self):
[fc99a86]41 listen(db.engine, 'connect', load_spatialite)
[be25db1]42 db.drop_all()
[5ec7c42]43 # create the tables whether the database already exists or not
[ae2ff15]44 db_setup(True)
45 self.db_content = db_test_setup.DatabaseContent()
46 self.db_content.setup()
[be25db1]47
48 def tearDown(self):
49 db.session.remove()
50 db.drop_all()
[ae2ff15]51 shutil.rmtree(self.tiles_cache)
52
53 def _create_test_tile(self, application):
54 self.tiles_cache = tempfile.mkdtemp(prefix='gnuboat-tests')
55 application.config['TILES_CACHE_PATH'] = self.tiles_cache
56
57 tile_path = os.path.join(self.tiles_cache, '100_100/256/15/17298/')
58 os.makedirs(tile_path)
59 img = Image.new('RGBA', (100, 100), (255, 0, 0, 0))
60 img.save(os.path.join(tile_path, "21435.png"), "PNG")
61
62 def check_key(self, key, value, data):
63 assert key in data, "{} not in data {}".format(key, data)
64 assert data[key] == value, "{} = {}".format(value, data[key])
Note: See TracBrowser for help on using the repository browser.