Ignore:
Timestamp:
Apr 10, 2020, 5:40:18 PM (7 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
debian/bullseye, master
Children:
5c9c247
Parents:
ce59b61
Message:
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mapservice/codegen/templates/__init__test.mustache

    rce59b61 rae2ff15  
    55from flask_cors import CORS
    66from flask_testing import TestCase
     7from flask_mail import Mail
    78from sqlalchemy.event import listen
    89from celery import Celery
     10import tempfile
     11import os
     12from PIL import Image
     13import shutil
    914
    1015from {{packageName}}.encoder import JSONEncoder
    1116from {{packageName}}.server_impl.database.Model import db, db_setup, load_spatialite
    12 from {{packageName}}.server_impl.demo import DbSetup as demoDbSetup
     17from . import db_test_setup
    1318
    1419class BaseTestCase(TestCase):
    … …  
    1823                application = app.app
    1924                CORS(application)
     25                mail = Mail()
    2026                application.json_encoder = JSONEncoder
    2127                app.add_api('openapi.yaml')
    … …  
    2430                celery = Celery(__name__, broker=application.config['CELERY_BROKER_URL'])
    2531                celery.config_from_object(application.config)
     32                mail.init_app(application)
    2633                db.init_app(application)
    2734                application.app_context().push()
     35               
     36                self._create_test_tile(application)
    2837               
    2938                return application
    … …  
    3342                db.drop_all()
    3443                # create the tables whether the database already exists or not
    35                 db_setup(False)
    36                 demoDbSetup.setup()
     44                db_setup(True)
     45                self.db_content = db_test_setup.DatabaseContent()
     46                self.db_content.setup()
    3747       
    3848        def tearDown(self):
    3949                db.session.remove()
    4050                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 TracChangeset for help on using the changeset viewer.