Changeset f9321aa for buildhelpers/codegen/templates/__init__test.mustache
- Timestamp:
- Apr 26, 2020, 5:02:25 PM (7 years ago)
- Branches:
- debian/bullseye, master
- Children:
- 62569d9
- Parents:
- 691c4ca
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
buildhelpers/codegen/templates/__init__test.mustache
r691c4ca rf9321aa 1 import logging 1 from flask_testing import TestCase 2 2 3 import flask 4 import connexion 5 from flask_cors import CORS 6 from flask_testing import TestCase 7 from flask_mail import Mail 8 from sqlalchemy.event import listen 9 from celery import Celery 10 import tempfile 11 import os 12 from PIL import Image 13 import shutil 14 15 from {{packageName}}.encoder import JSONEncoder 16 from {{packageName}}_impl.database.Model import ( 17 db, db_setup, load_spatialite 3 from {{packageName}}_impl.tests import ( 4 create_app as orig_create_app, 5 setUp as orig_setUp, 6 tearDown as orig_tearDown 18 7 ) 19 from {{packageName}}_impl.tests import db_test_setup20 8 21 9 class BaseTestCase(TestCase): 22 10 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) 27 mail = Mail() 28 application.json_encoder = JSONEncoder 29 app.add_api('openapi.yaml') 30 31 application.config.from_object('{{packageName}}_impl.Config.TestingConfig') 32 application.template_folder = os.path.join(os.path.dirname(__file__), '../../mapservice_impl/templates') 33 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL']) 34 celery.config_from_object(application.config) 35 mail.init_app(application) 36 db.init_app(application) 37 application.app_context().push() 38 39 self._create_test_tile(application) 40 41 return application 11 return orig_create_app(self) 42 12 43 13 def setUp(self): 44 listen(db.engine, 'connect', load_spatialite) 45 db.drop_all() 46 # create the tables whether the database already exists or not 47 db_setup(True) 48 self.db_content = db_test_setup.DatabaseContent() 49 self.db_content.setup() 14 orig_setUp(self) 50 15 51 16 def tearDown(self): 52 db.session.remove() 53 db.drop_all() 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") 17 orig_tearDown(self) 64 18 65 19 def check_key(self, key, value, data):
Note:
See TracChangeset
for help on using the changeset viewer.
