def test_exception(self): # Test MetadataBroker throwing a conn away after exception first_conn = None broker = MetadataBroker(':memory:') broker.initialize(normalize_timestamp('1')) with broker.get() as conn: first_conn = conn try: with broker.get() as conn: self.assertEqual(first_conn, conn) raise Exception('OMG') except Exception: pass self.assert_(broker.conn is None)
def test_creation(self): # Test MetadataBroker.__init__ broker = MetadataBroker(':memory:') self.assertEqual(broker.db_file, ':memory:') got_exc = False try: with broker.get() as conn: pass except Exception: got_exc = True self.assert_(got_exc) broker.initialize(normalize_timestamp('1')) with broker.get() as conn: curs = conn.cursor() curs.execute('SELECT 1') self.assertEqual(curs.fetchall()[0][0], 1)
def _get_metadata_broker(self, **kwargs): """ Returns an instance of the DB abstraction layer object (broker) """ return MetadataBroker(self.db_ip, self.db_port, self.db_user, self.db_pw)
def _get_metadata_broker(self, **kwargs): """ Returns an instance of the DB abstraction layer object (broker) """ kwargs.setdefault('db_file', self.db_file) return MetadataBroker(**kwargs)