def test_get_int(self): i = testdata.get_int() self.assertGreater(i, 0) i = testdata.get_int(1, 5) self.assertGreaterEqual(i, 1) self.assertGreaterEqual(5, i)
def create_message(self, name="", interface=None, **fields): name = self.get_name(name) interface = interface or self.get_interface() if not fields: fields[testdata.get_ascii()] = testdata.get_int() fields[testdata.get_ascii()] = testdata.get_int() msg = interface.create_message(name, fields=fields) type(self).interfaces[name].append(interface) return msg
def test_create_pk(self): """there was a bug that if you set the pk then it wouldn't set the updated or created datestamps, this makes sure that is fixed""" orm_class = self.get_orm_class() pk = testdata.get_int() o = orm_class.create(foo=1, bar="1", _id=pk) self.assertEqual(pk, o.pk)
def test_unicode(self): """ Jarid was having encoding issues, so I'm finally making sure prom only ever returns unicode strings """ orm_class = self.get_orm_class() table_name = self.get_table_name() orm_class.schema = self.get_schema( self.get_table_name(), foo=Field(unicode, True), bar=Field(str, True), che=Field(str, False), baz=Field(int, False), ) t = orm_class.create( foo=testdata.get_unicode_name(), bar=testdata.get_unicode_words(), che=testdata.get_unicode_words().encode('utf-8'), baz=testdata.get_int(1, 100000) ) t2 = orm_class.query.get_pk(t.pk) self.assertEqual(t.foo, t2.foo) self.assertEqual(t.bar, t2.bar) #self.assertEqual(t.che, t2.che.encode('utf-8')) self.assertEqual(t.che.decode("utf-8"), t2.che) self.assertTrue(isinstance(t.baz, int))
def test_message_encode_decode(self): fields = {"foo": testdata.get_words(), "bar": testdata.get_int()} i = self.get_encrypted_interface() im = self.create_message(name="message-lifecycle", interface=i, **fields) cipher_text = im.body im2 = i.create_message(name="message-lifecycle", body=cipher_text) self.assertEqual(fields, im2.fields)
def test_ack_message(self): m = self.get_msg(foo=testdata.get_int()) mcls = m.__class__ m.send() with mcls.recv() as m2: raise AckMessage() with mcls.recv_for(timeout=1) as m2: self.assertEqual(None, m2)
def test_release_1(self): m = self.get_msg(foo=testdata.get_int()) mcls = m.__class__ m.send() with self.assertRaises(RuntimeError): with mcls.recv() as m2: raise RuntimeError() with mcls.recv() as m2: self.assertEqual(m2.foo, m.foo)
def test_release(self): m = self.get_msg() mcls = m.__class__ m.foo = testdata.get_int() m.send() with self.assertRaises(RuntimeError): with mcls.recv() as m2: raise RuntimeError() with mcls.recv() as m2: self.assertEqual(m2.foo, m.foo)
def test_release_message(self): m = self.get_msg(foo=testdata.get_int()) mcls = m.__class__ m.send() with mcls.recv() as m2: raise ReleaseMessage(2) with mcls.recv_for(1) as m2: self.assertEqual(None, m2) time.sleep(1) with mcls.recv_for(1) as m2: self.assertEqual(m.foo, m2.foo)
def get_encrypted_interface(self, config=None): """get a connected interface""" options = {} if testdata.yes(): options['key'] = testdata.create_file("/morp.key", testdata.get_ascii(100)) else: options['key'] = testdata.get_ascii(testdata.get_int(10, 200)) if config: for k, v in options.items(): config.options[k] = v else: config = self.get_config(**options) return self.get_interface(config)
def test_backoff(self): # TODO make this work with a backoff, this test works but doesn't do any # sort of visibility backoff m = self.get_msg() mcls = m.__class__ foo = testdata.get_int() m.foo = foo m.send() count = 0 for x in range(2): with self.assertRaises(RuntimeError): with mcls.recv() as m2: self.assertGreater(m2.interface_msg._count, count) count = m2.interface_msg._count raise RuntimeError() with mcls.recv() as m2: self.assertGreater(m2.interface_msg._count, count) self.assertEqual(m2.foo, m.foo)
def get_item(item=None, **kwargs): if item: body = dict(item.newest.body) body.update(kwargs) body.setdefault("uuid", item.uuid) kwargs = body price = kwargs.pop("price", testdata.get_int(1000)) uuid = kwargs.pop("uuid", testdata.get_hash()) kwargs.setdefault("url", testdata.get_url()) kwargs.setdefault("digital", testdata.get_bool()) kwargs.setdefault("image", testdata.get_url()) kwargs.setdefault("title", testdata.get_words()) if isinstance(price, float): kwargs["price"] = price price = int(price * 100.0) else: kwargs["price"] = float(price) * 0.01 it = Item(price=price, body=kwargs, uuid=uuid) return it