def testNotEqual(self): session = self.session() inst = yield session.add( Instrument(name='erz22', type='future', ccy='EUR')) inst2 = yield session.add( Instrument(name='edz24', type='future', ccy='USD')) id = inst.id b = yield self.query().get(id=id) self.assertEqual(b.id, id) self.assertFalse(inst2 == b) self.assertTrue(inst2 != b)
def test_simple(self): d = odm.model_to_dict(Instrument) self.assertFalse(d) inst = yield self.session().add( Instrument(name='erz12', type='future', ccy='EUR')) d = odm.model_to_dict(inst) self.assertTrue(len(d), 3)
def testSimple(self): inst = yield self.session().add( Instrument(name='erz12', type='future', ccy='EUR')) p = pickle.dumps(inst) inst2 = pickle.loads(p) self.assertEqual(inst, inst2) self.assertEqual(inst.name, inst2.name) self.assertEqual(inst.type, inst2.type) self.assertEqual(inst.ccy, inst2.ccy)
def testUniqueId(self): '''Test model instance unique id across different model''' inst = Instrument(name='erk12', type='future', ccy='EUR') self.assertRaises(inst.DoesNotExist, lambda: inst.uuid) yield self.session().add(inst) v = inst.uuid.split('.') # <<model hash>>.<<instance id>> self.assertEqual(len(v), 2) self.assertEqual(v[0], inst._meta.hash) self.assertEqual(v[1], str(inst.id))
def testHash(self): '''Test model instance hash''' inst = Instrument(name='erh12', type='future', ccy='EUR') h0 = hash(inst) self.assertTrue(h0) inst = yield self.session().add(inst) h = hash(inst) self.assertTrue(h) self.assertNotEqual(h, h0)
def testTempDictionary(self): session = self.session() inst = yield session.add( Instrument(name='erz17', type='future', ccy='EUR')) self.assertTrue('cleaned_data' in inst._dbdata) p = pickle.dumps(inst) inst2 = pickle.loads(p) self.assertFalse('cleaned_data' in inst2._dbdata) yield session.add(inst2) self.assertTrue('cleaned_data' in inst._dbdata)
def testEqual(self): session = self.session() inst = yield session.add( Instrument(name='erm12', type='future', ccy='EUR')) id = inst.id b = yield self.query().get(id=id) self.assertEqual(b.id, id) self.assertTrue(inst == b) self.assertFalse(inst != b) f = yield session.add(Fund(name='bla', ccy='EUR')) self.assertFalse(inst == f) self.assertTrue(inst != f)