Esempio n. 1
0
class DatabaseTest(unittest.TestCase):
    """Tests ConfigManager and local/remote config access."""
    def setUp(self):
        self.session = Context().getSession()

    def tearDown(self):
        all_data = self.session.query(Test_Table).delete()
        self.session.commit()
        Context().closeSession()

    def testCreateData(self):
        for x in range(O):
            obj = Test_Table(
                key=''.join(
                    random.SystemRandom().choice(string.ascii_uppercase +
                                                 string.digits)
                    for _ in range(M)),
                val=''.join(
                    random.SystemRandom().choice(string.ascii_uppercase +
                                                 string.digits)
                    for _ in range(N)))
            try:
                self.session.add(obj)
                self.session.commit()
            except:
                self.session.rollback()
                #raise
            finally:
                self.session.close()
                Context().closeSession()

        self.assertEqual(self.session.query(Test_Table).count(), O)
        Context().closeSession()
Esempio n. 2
0
 def add_dataset(self, obj):
     session = Context().getSession()
     ds_exists = session.query(Catalog_Dataset).filter(
         Catalog_Dataset.entity_id == obj.entity_id).filter(
             Catalog_Dataset.tile_identifier == obj.tile_identifier).filter(
                 Catalog_Dataset.acq_time == obj.acq_time)
     if not ds_exists.count():
         try:
             c = Catalog_Dataset(**dict(obj))
             session.add(c)
             session.commit()
         except:
             session.rollback()
             raise
         finally:
             session.close()
             Context().closeSession()
     return True