source: buildhelpers/codegen/templates/__init__test.mustache@ 488be44

debian/bullseye
Last change on this file since 488be44 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
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}}_impl.database.Model import (
17 db, db_setup, load_spatialite
18)
19from {{packageName}}_impl.tests import db_test_setup
20
21class BaseTestCase(TestCase):
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)
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
42
43 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()
50
51 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")
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.