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
Location:
src/mapservice/server_impl
Files:
20 moved

Legend:

Unmodified
Added
Removed
  • src/mapservice/server_impl/Config.py

    rce59b61 rae2ff15  
    3434        TESTING = False
    3535        CREATE_TEST_DATABASE = False
    36         SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
    3736        SQLALCHEMY_TRACK_MODIFICATIONS = False
    3837        MAIL_SERVER = 'localhost'
    … …  
    6867        DEBUG = True
    6968        CREATE_TEST_DATABASE = True
     69        SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/test.db'
    7070        MAPSERVICE_WEBCLIENT = 'http://localhost:8081'
    7171        #SERVER_NAME = 'gnuboat-mapservice:8080'
    … …  
    8080        """
    8181        TESTING = True
    82         DEBUG = True
     82        DEBUG = False
    8383        CELERY_BROKER_URL = ''
     84        SQLALCHEMY_DATABASE_URI = 'sqlite:////tmp/gnuboat-ci-tests.db'
  • src/mapservice/server_impl/__init__.py

    rce59b61 rae2ff15  
    5353        def load_spatialite_extension(dbapi_conn, connection_record):
    5454                load_spatialite(dbapi_conn, connection_record)
     55                       
    5556
    5657        if flask.current_app.config['CREATE_TEST_DATABASE'] == True:
  • src/mapservice/server_impl/controllers/WatersController.py

    rce59b61 rae2ff15  
    4343                stakeholder = User.query.filter_by(username=stakeholder).all()
    4444                if len(stakeholder) != 1:
    45                         raise MapserviceBadRequest(details='Stakeholder not found')
     45                        raise MapserviceNotFound(details='Stakeholder not found')
    4646                stakeholder = stakeholder[0]
    4747               
  • src/mapservice/server_impl/database/Model.py

    rce59b61 rae2ff15  
    6666                        'lastName': "",
    6767                        'activated': user.activated,
    68                         'licenseAccepted': user.license_accepted,
     68                        'licenseAccepted': user.license_accepted
    6969                }
    7070                if user.first_name is not None:
    … …  
    374374        log = db.relationship("Log", backref=db.backref("queue"), lazy=True)
    375375
    376 def db_setup(if_not_exists = True):
    377         if not database_exists(db.engine.url) or not if_not_exists:
     376def db_setup(force = False):
     377        if not database_exists(db.engine.url) or force:
    378378                create_database(db.engine.url)
    379379                if 'sqlite' in flask.current_app.config['SQLALCHEMY_DATABASE_URI']:
    … …  
    395395        for path in paths:
    396396                if _load_spatialite_from_path(path, dbapi_conn, connection_record):
    397                         return
     397                        return True
    398398        raise FileNotFoundError('mod_spatialite not found in folders {}'.format(', '.join(paths)))
    399399                       
    … …  
    401401        for path in Path(search_path).rglob('mod_spatialite.so*'):
    402402                if os.path.exists(path):
    403                         print('Enabling spatial lite extension. This may take a while')
     403                        if flask.current_app.config['DEBUG'] and (not 'TESTING' in flask.current_app.config or not flask.current_app.config['TESTING']):
     404                                print('Enabling spatial lite extension. This may take a while')
    404405                        # From https://geoalchemy-2.readthedocs.io/en/latest/spatialite_tutorial.html
    405406                        dbapi_conn.enable_load_extension(True)
  • src/mapservice/server_impl/demo/DbSetup.py

    rce59b61 rae2ff15  
    2626        db_setup()
    2727       
    28         print("CREATING DATABASE TEST CONTENT...")
     28        print("CREATING DATABASE DEMO CONTENT...")
    2929        with db.session.no_autoflush:
    3030                test_user_john = None
    … …  
    5050                        db.session.add(test_user_jane)
    5151                        db.session.commit()
    52                
     52                       
    5353                if len(ApiKey.query.filter_by(key='DelApiKey4711').all()) < 1:
    5454                        db.session.add(ApiKey(user=test_user_jane, key='DelApiKey4711'))
    5555                        db.session.commit()
    56                 if len(ApiKey.query.filter_by(key='test_key').all()) < 1:
    57                         db.session.add(ApiKey(user=test_user_jane, key='test_key'))
    58                         db.session.commit()
    59                 if len(ApiKey.query.filter_by(key='ApiKey4712').all()) < 1:
    60                         db.session.add(ApiKey(user=test_user_jane, key='ApiKey4712'))
     56                if len(ApiKey.query.filter_by(key='test_key_jane').all()) < 1:
     57                        db.session.add(ApiKey(user=test_user_jane, key='test_key_jane'))
    6158                        db.session.commit()
    6259               
    … …  
    126123def _sample_log_add(water, gauge, gauge_height, device, submitter, log_file):
    127124        if len(Log.query.filter_by(submitter=submitter).all()) > 0:
    128                 return
    129        
    130         if not 'CELERY_BROKER_URL' in flask.current_app.config or not flask.current_app.config['CELERY_BROKER_URL']:
    131                 print('Do not add log, since their is no CELERY_BROKER_URL configured')
    132                 return
     125                return None
    133126       
    134127        log = Log(submitter=submitter, water=water, device=device, gauge=gauge, gauge_height=0, comment='Demo Log from {}'.format(log_file))
    135128        db.session.add(log)
    136129        db.session.commit()
     130       
     131        if not 'CELERY_BROKER_URL' in flask.current_app.config or not flask.current_app.config['CELERY_BROKER_URL']:
     132                print('Do not add log, since their is no CELERY_BROKER_URL configured')
     133                return log
    137134       
    138135        with open(log_file, 'r') as logfile:
    … …  
    152149        # request log parsing
    153150        log_process.delay(log.id, data)
     151        return log
Note: See TracChangeset for help on using the changeset viewer.