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
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 celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
31 celery.config_from_object(application.config)
32 mail.init_app(application)
33 db.init_app(application)
34 application.app_context().push()
35
36 self._create_test_tile(application)
37
38 return application
39
40 def setUp(self):
41 listen(db.engine, 'connect', load_spatialite)
42 db.drop_all()
43 # create the tables whether the database already exists or not
44 db_setup(True)
45 self.db_content = db_test_setup.DatabaseContent()
46 self.db_content.setup()
47
48 def tearDown(self):
49 db.session.remove()
50 db.drop_all()
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.