def test_table_queries(self): self.engine.execute(tables.Queues.insert(), id=1, project='test', name='zaqar', metadata=utils.json_encode('aaaa')) self.engine.execute(tables.Messages.insert(), id=1, qid=1, ttl=10, body=utils.json_encode('bbbb'), client='a', created=datetime.datetime.now()) self.engine.execute(tables.Claims.insert(), id=1, qid=1, ttl=10, created=datetime.datetime.now()) rs = self.engine.execute(tables.Claims.select()) row = rs.fetchone() self.assertEqual(row.id, 1) self.assertEqual(row.qid, 1) self.assertEqual(row.ttl, 10) self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1)) rs = self.engine.execute(tables.Claims.select()) row = rs.fetchone() self.assertIsNone(row)
def test_table_queries(self): self.engine.execute(tables.Queues.insert(), id=1, project='test', name='zaqar', metadata=utils.json_encode('aaaa')) self.engine.execute(tables.Messages.insert(), id=1, qid=1, ttl=10, body=utils.json_encode('bbbb'), client='a', created=datetime.datetime.now()) self.engine.execute(tables.Claims.insert(), id=1, qid=1, ttl=10, created=datetime.datetime.now()) rs = self.engine.execute(tables.Claims.select()) row = rs.fetchone() self.assertEqual(row.id, 1) self.assertEqual(row.qid, 1) self.assertEqual(row.ttl, 10) self.engine.execute(tables.Claims.delete(tables.Claims.c.id == 1)) rs = self.engine.execute(tables.Claims.select()) row = rs.fetchone() self.assertIsNone(row)
def create(self, name, metadata=None, project=None): if project is None: project = '' try: smeta = utils.json_encode(metadata or {}) ins = tables.Queues.insert().values(project=project, name=name, metadata=smeta) res = self.driver.run(ins) except sa.exc.IntegrityError: return False return res.rowcount == 1
def create(self, name, metadata=None, project=None): if project is None: project = '' try: smeta = utils.json_encode(metadata or {}) ins = tables.Queues.insert().values(project=project, name=name, metadata=smeta) res = self.driver.run(ins) except sa.exc.IntegrityError: return False return res.rowcount == 1
def create(self, name, weight, uri, options=None): opts = None if options is None else utils.json_encode(options) try: stmt = sa.sql.expression.insert(tables.Pools).values( name=name, weight=weight, uri=uri, options=opts ) self._conn.execute(stmt) except sa.exc.IntegrityError: # TODO(cpp-cabrera): merge update/create into a single # method with introduction of upsert self.update(name, weight=weight, uri=uri, options=options)
def create(self, name, weight, uri, options=None): opts = None if options is None else utils.json_encode(options) try: stmt = sa.sql.expression.insert(tables.Pools).values(name=name, weight=weight, uri=uri, options=opts) self._conn.execute(stmt) except sa.exc.IntegrityError: # TODO(cpp-cabrera): merge update/create into a single # method with introduction of upsert self.update(name, weight=weight, uri=uri, options=options)
def set_metadata(self, name, metadata, project): if project is None: project = '' update = (tables.Queues.update().where( sa.and_(tables.Queues.c.project == project, tables.Queues.c.name == name)).values( metadata=utils.json_encode(metadata))) res = self.driver.run(update) try: if res.rowcount != 1: raise errors.QueueDoesNotExist(name, project) finally: res.close()
def set_metadata(self, name, metadata, project): if project is None: project = '' update = (tables.Queues.update(). where(sa.and_( tables.Queues.c.project == project, tables.Queues.c.name == name)). values(metadata=utils.json_encode(metadata))) res = self.driver.run(update) try: if res.rowcount != 1: raise errors.QueueDoesNotExist(name, project) finally: res.close()
def update(self, name, **kwargs): # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid # overwriting the existing options field with None, since that # one can be null. names = ('uri', 'weight', 'options') fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None) assert fields, '`weight`, `uri`, or `options` not found in kwargs' if 'options' in fields: fields['options'] = utils.json_encode(fields['options']) stmt = sa.sql.update(tables.Pools).where( tables.Pools.c.name == name).values(**fields) res = self._conn.execute(stmt) if res.rowcount == 0: raise errors.PoolDoesNotExist(name)
def update(self, name, **kwargs): # NOTE(cpp-cabrera): by pruning None-valued kwargs, we avoid # overwriting the existing options field with None, since that # one can be null. names = ('uri', 'weight', 'options') fields = common_utils.fields(kwargs, names, pred=lambda x: x is not None) assert fields, '`weight`, `uri`, or `options` not found in kwargs' if 'options' in fields: fields['options'] = utils.json_encode(fields['options']) stmt = sa.sql.update( tables.Pools).where(tables.Pools.c.name == name).values(**fields) res = self._conn.execute(stmt) if res.rowcount == 0: raise errors.PoolDoesNotExist(name)
def it(): for m in messages: yield dict(qid=qid, ttl=m['ttl'], body=utils.json_encode(m['body']), client=str(client_uuid))
def it(): for m in messages: yield dict(qid=qid, ttl=m['ttl'], body=utils.json_encode(m['body']), client=str(client_uuid))