Beispiel #1
0
 def setUp(self):
     store_factory = StoreFactory(
         create_engine("sqlite:///:memory:", echo=True))
     store = store_factory.create()
     self.admin_user_id = store.add_user(
         User(name="admin",
              telephone="1",
              email="*****@*****.**",
              is_active=True,
              is_admin=True))
     self.manager_user_id = store.add_user(
         User(name="manager",
              telephone="2",
              email="*****@*****.**",
              is_active=True))
     self.store = store
Beispiel #2
0
def test_load_test_data():
    """Ensure consitency between test data used in plots and BD schema
  
  e.g. between load_test_data and db.get_bed_counts
  """
    # TODO: cache generation of in memory DB with fake data into a pytest fixture
    df = load_test_data()['bedcounts']

    # duplicate columns with "date"
    del df['datetime']

    store = StoreFactory(create_engine("sqlite:///:memory:")).create()
    populate_store_fake(store)
    df_db = to_pandas(store.get_bed_counts())
    df_db = normalize_colum_names(df_db, 'bedcounts')
    # All bedcount columns in tests data used for plots must belong to the DB schema
    missing_columns = set(df.columns).difference(df_db.columns)
    assert not missing_columns
Beispiel #3
0
class WipeTest(absltest.TestCase):
    def wipe_close_and_reconnect(self,
                                 keep_beds=False,
                                 reset_admin=False,
                                 admin_email=None,
                                 admin_pass=None):
        wipe_db(self.store, keep_beds, reset_admin, admin_email, admin_pass)
        self.store._session.close()
        self.store = self.store_factory.create()

    def setUp(self):
        self.store_factory = StoreFactory(
            create_engine("sqlite:///:memory:", echo=False))
        self.store = self.store_factory.create()
        populate_store_fake(self.store)

    def test_wipe(self):
        self.wipe_close_and_reconnect(keep_beds=False)
        users = list(self.store.get_users())
        self.assertItemsEqual([user.name for user in users],
                              itertools.repeat("Jean Dumont", len(users)))
        self.assertItemsEqual([user.email for user in users],
                              itertools.repeat("*****@*****.**",
                                               len(users)))
        bed_counts = list(self.store.get_bed_counts(None))
        self.assertItemsEqual([bc.n_covid_free for bc in bed_counts],
                              itertools.repeat(2, len(bed_counts)))

    def test_keep_beds(self):
        self.wipe_close_and_reconnect(keep_beds=True)
        users = list(self.store.get_users())
        self.assertItemsEqual([user.name for user in users],
                              itertools.repeat("Jean Dumont", len(users)))
        bed_counts = list(self.store.get_bed_counts(None))
        self.assertFalse(all([bc.n_covid_free == 2 for bc in bed_counts]))

    def test_reset_admin(self):
        email = "*****@*****.**"
        self.wipe_close_and_reconnect(keep_beds=False,
                                      reset_admin=True,
                                      admin_email=email,
                                      admin_pass="******")
        admins = list(self.store.get_admins())
        self.assertTrue(len(admins) == 1)
        self.assertTrue(admins[0].email == email)
Beispiel #4
0
 def setUp(self):
     self.store_factory = StoreFactory(
         create_engine("sqlite:///:memory:", echo=False))
     self.store = self.store_factory.create()
     populate_store_fake(self.store)
Beispiel #5
0
def wipe_db_path(path, keep_beds, reset_admin, admin_email, admin_pass):
    store_factory = StoreFactory(create_engine("sqlite:///" + path))
    wipe_db(store_factory.create(), keep_beds, reset_admin, admin_email,
            admin_pass)