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
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 #3
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)
Beispiel #4
0
 def setUp(self):
   self.engine = create_engine("sqlite:///:memory:", echo=False)
   store_factory = StoreFactory(self.engine)
   self.store = store_factory.create()
   populate_store_fake(self.store)