| 1 | '''
|
|---|
| 2 | Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
|
|---|
| 3 |
|
|---|
| 4 | This program is free software: you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation, either version 3 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 16 | '''
|
|---|
| 17 |
|
|---|
| 18 | import os
|
|---|
| 19 | import pytz
|
|---|
| 20 | import flask
|
|---|
| 21 |
|
|---|
| 22 | from ..server_impl.database.Model import db, User, ApiKey, Water, OsmType, Gauge, Device, Log, Queue, ProcessingStatus, db_setup
|
|---|
| 23 | from ..server_impl.demo import DbSetup as demoDbSetup
|
|---|
| 24 | from ..server_impl.tasks.tasks import log_process
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 | class DatabaseContent:
|
|---|
| 28 | def __init__(self):
|
|---|
| 29 | test_user = None
|
|---|
| 30 | test_water = None
|
|---|
| 31 | test_gauge = None
|
|---|
| 32 | test_device = None
|
|---|
| 33 | test_log = None
|
|---|
| 34 |
|
|---|
| 35 | def setup(self):
|
|---|
| 36 | db_setup()
|
|---|
| 37 |
|
|---|
| 38 | print("CREATING DATABASE TEST CONTENT...")
|
|---|
| 39 | with db.session.no_autoflush:
|
|---|
| 40 | self.test_user = User.factory(
|
|---|
| 41 | 'autotests', 'autotests', 'auto@example.org'
|
|---|
| 42 | )
|
|---|
| 43 | self.test_user.activated = True
|
|---|
| 44 | self.test_user.first_name = 'Autotests'
|
|---|
| 45 | self.test_user.license_accepted = True
|
|---|
| 46 | db.session.add(self.test_user)
|
|---|
| 47 | db.session.commit()
|
|---|
| 48 |
|
|---|
| 49 | user_activation = User.factory(
|
|---|
| 50 | 'test_user_activation', 'test_user_activation',
|
|---|
| 51 | 'test@example.org'
|
|---|
| 52 | )
|
|---|
| 53 | user_activation.activated = False
|
|---|
| 54 | user_activation.activation_code = 'dac9630aec642a428cd73f4be0a03569'
|
|---|
| 55 | user_activation.first_name = 'Autotests'
|
|---|
| 56 | user_activation.license_accepted = True
|
|---|
| 57 | db.session.add(user_activation)
|
|---|
| 58 | db.session.commit()
|
|---|
| 59 |
|
|---|
| 60 | db.session.add(ApiKey(user=self.test_user, key='test_key'))
|
|---|
| 61 | db.session.add(ApiKey(user=self.test_user, key='test_key_delete'))
|
|---|
| 62 | db.session.commit()
|
|---|
| 63 |
|
|---|
| 64 | self.test_water = Water(
|
|---|
| 65 | name='Test Water',
|
|---|
| 66 | manager=self.test_user,
|
|---|
| 67 | osm_id=1756854,
|
|---|
| 68 | osm_type=OsmType.Relation
|
|---|
| 69 | )
|
|---|
| 70 | db.session.add(self.test_water)
|
|---|
| 71 | db.session.commit()
|
|---|
| 72 |
|
|---|
| 73 | self.test_gauge = Gauge(
|
|---|
| 74 | name='test_gauge',
|
|---|
| 75 | manager=self.test_user,
|
|---|
| 76 | water=self.test_water,
|
|---|
| 77 | location='SRID=4326;POINT(-90.136111 29.934722)',
|
|---|
| 78 | reference_water_level_gauge_height=3
|
|---|
| 79 | )
|
|---|
| 80 | db.session.add(self.test_gauge)
|
|---|
| 81 | db.session.commit()
|
|---|
| 82 |
|
|---|
| 83 | self.test_device = Device(
|
|---|
| 84 | name='Test Device', owner=self.test_user, sensor_depth=0.2
|
|---|
| 85 | )
|
|---|
| 86 | db.session.add(self.test_device)
|
|---|
| 87 | db.session.commit()
|
|---|
| 88 |
|
|---|
| 89 | log_file = os.path.join(
|
|---|
| 90 | os.path.dirname(__file__), 'data/nmea0183-2017-12-09.log'
|
|---|
| 91 | )
|
|---|
| 92 | self.test_log = demoDbSetup._sample_log_add(
|
|---|
| 93 | self.test_water, self.test_gauge, 0, self.test_device,
|
|---|
| 94 | self.test_user, log_file
|
|---|
| 95 | )
|
|---|
| 96 |
|
|---|
| 97 | print("...Finished")
|
|---|