source: src/mapservice/tests/db_test_setup.py@ ff880df

debian/bullseye
Last change on this file since ff880df 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: 2.8 KB
Line 
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
18import os
19import pytz
20import flask
21
22from ..server_impl.database.Model import db, User, ApiKey, Water, OsmType, Gauge, Device, Log, Queue, ProcessingStatus, db_setup
23from ..server_impl.demo import DbSetup as demoDbSetup
24from ..server_impl.tasks.tasks import log_process
25
26class DatabaseContent:
27 def __init__(self):
28 test_user = None
29 test_water = None
30 test_gauge = None
31 test_device = None
32 test_log = None
33
34 def setup(self):
35 db_setup()
36
37 print("CREATING DATABASE TEST CONTENT...")
38 with db.session.no_autoflush:
39 self.test_user = User.factory('autotests', 'autotests', 'auto@example.org')
40 self.test_user.activated = True
41 self.test_user.first_name = 'Autotests'
42 self.test_user.license_accepted = True
43 db.session.add(self.test_user)
44 db.session.commit()
45
46 user_activation = User.factory('test_user_activation', 'test_user_activation', 'test@example.org')
47 user_activation.activated = False
48 user_activation.activation_code = 'dac9630aec642a428cd73f4be0a03569'
49 user_activation.first_name = 'Autotests'
50 user_activation.license_accepted = True
51 db.session.add(user_activation)
52 db.session.commit()
53
54 db.session.add(ApiKey(user=self.test_user, key='test_key'))
55 db.session.add(ApiKey(user=self.test_user, key='test_key_delete'))
56 db.session.commit()
57
58 self.test_water = Water(name='Test Water', manager=self.test_user, osm_id=1756854, osm_type=OsmType.Relation)
59 db.session.add(self.test_water)
60 db.session.commit()
61
62 self.test_gauge = Gauge(name='test_gauge', manager=self.test_user, water=self.test_water, location='SRID=4326;POINT(-90.136111 29.934722)', reference_water_level_gauge_height=3)
63 db.session.add(self.test_gauge)
64 db.session.commit()
65
66 self.test_device = Device(name='Test Device', owner=self.test_user, sensor_depth=0.2)
67 db.session.add(self.test_device)
68 db.session.commit()
69
70 log_file = os.path.join(os.path.dirname(__file__), 'data/nmea0183-2017-12-09.log')
71 self.test_log = demoDbSetup._sample_log_add(self.test_water, self.test_gauge, 0, self.test_device, self.test_user, log_file)
72
73 print("...Finished")
Note: See TracBrowser for help on using the repository browser.