source: buildhelpers/codegen/templates/__init__test.mustache@ 61489e6

debian/bullseye
Last change on this file since 61489e6 was 43fd35c, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago

Refactored code to have one gnuboat python structure

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