コード例 #1
0
    def test_bedcount_update(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))

            # Make sure you can't insert without a valid icu_id
            with self.assertRaises(ValueError):
                sqldb.update_bedcount(1, "test", 10, 9, 8, 7, 6, 5, 4)
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            sqldb.upsert_icu("ICU2", "dep1", "city1", 3.44, 42.3, "0102")

            # Generate some bed updates:
            for i in [1, 2]:
                for j in range(10):
                    time.sleep(0.01)
                    sqldb.update_bedcount(i, "test", 10, 9, 8, 7, 6, 5, 4)
            bedcount = sqldb.get_bedcount()
            self.assertLen(bedcount, 2)

            # Make sure the returned updates are the most recent
            for i in [1, 2]:
                res = sqldb.pd_execute(
                    f"SELECT MAX(update_ts) as max_ts FROM bed_updates WHERE icu_id = {i}"
                )
                max_ts = res.iloc[0]["max_ts"]
                self.assertEqual(
                    bedcount[bedcount["icu_id"] == i].iloc[0]["update_ts"],
                    max_ts)
コード例 #2
0
ファイル: server.py プロジェクト: psc-g/coviduci-ec
 def __init__(self, config, port):
     self.config = config
     self.port = port
     self.routes = []
     self.token_encoder = token.TokenEncoder(self.config)
     self.writing_queue = queues.Queue()
     self.db = sqlite.SQLiteDB(self.config.db.sqlite_path,
                               self.token_encoder)
     logging.info('Opened db {}'.format(self.config.db.sqlite_path))
     self.make_app()
     self.callbacks = [
         queue_writer.QueueWriter(self.writing_queue, self.db)
     ]
コード例 #3
0
 def __init__(self, config, port):
   self.config = config
   self.port = port
   self.routes = []
   self.token_encoder = token.TokenEncoder(self.config)
   self.writing_queue = queues.Queue()
   self.db = sqlite.SQLiteDB(self.config.db.sqlite_path, self.token_encoder)
   logging.info('Opened db {}'.format(self.config.db.sqlite_path))
   self.make_app()
   self.callbacks = [
     queue_writer.QueueWriter(self.writing_queue, self.db)
   ]
   locale_path = Path(__file__).parent.parent.joinpath('locale')
   locale.load_gettext_translations(locale_path, 'messages')
コード例 #4
0
    def test_user_creation(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))

            # Make sure you can't add a user with non-existant ICU
            with self.assertRaises(ValueError):
                sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")

            # Check normal insertion
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")

            with self.assertRaises(sqlite3.IntegrityError):
                sqldb.add_user("ICU1", "Bob", "+33698158092", "Chercheur")
            users = sqldb.get_users()
コード例 #5
0
    def test_icu_creation(self):
        with tempfile.TemporaryDirectory() as tmp_folder:
            sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))
            sqldb.upsert_icu("ICU1", "dep1", "city1", 3.44, 42.3, "0102")
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU1"].iloc[0]["dept"],
                             "dep1")

            sqldb.upsert_icu("ICU2", "dep2", "city2", 3.44, 42.3)
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU2"].iloc[0]["dept"],
                             "dep2")

            sqldb.upsert_icu("ICU1", "dep3", "city3", 3.44, 42.3, "0103")
            icus = sqldb.get_icus()
            self.assertEqual(icus[icus["icu_name"] == "ICU1"].iloc[0]["dept"],
                             "dep3")
            self.assertEqual(
                icus[icus["icu_name"] == "ICU1"].iloc[0]["telephone"], "0103")
            self.assertEqual(sqldb.get_icu_id_from_name("ICU1"), 1)
            self.assertEqual(sqldb.get_icu_id_from_name("ICU2"), 2)
コード例 #6
0
def main(unused_argv):
    cfg = config.Config(FLAGS.config, env_path=FLAGS.dotenv_path)
    token_encoder = token.TokenEncoder(cfg)
    sqldb = sqlite.SQLiteDB(cfg.db.sqlite_path, token_encoder)
    sqldb.create_users()
コード例 #7
0
 def test_init(self):
     with tempfile.TemporaryDirectory() as tmp_folder:
         sqldb = sqlite.SQLiteDB(os.path.join(tmp_folder, "test.db"))