def test_setnx_already_set(self): ts = rom.Timestamp(self.conn, "ts") ts.setnx(1.23) rv = ts.setnx(4.56) self.assertEqual(False, rv) self.assertEqual(1.23, ts.value)
def test_cachable(self): ts = rom.Timestamp(connection=self.conn, key="ts") ts.setnx() value = ts.value self.conn.set(ts.key, str(0.0)) self.assertEqual(str(0.0), self.conn.get(ts.key)) self.assertEqual(value, ts.value)
def test_delete(self): ts = rom.Timestamp(connection=self.conn, key="ts") val = ts.setnx() self.assertTrue(float(val) > 0) ts.delete() self.assertRaises(KeyError, getattr, ts, "value") val2 = ts.setnx() self.assertTrue(float(val2) >= float(val))
def test_copy(self): # Patch "now" on the timestamp object (which returns the current time # in floating point seconds) to return a custom sequence with patch.object(rom.Timestamp, "now") as mock_now: mock_now.__get__ = Mock(return_value='1.1') ts1 = rom.Timestamp(connection=self.conn, key="ts1") ts1.setnx() ts2 = ts1.copy("ts2") self.assertEqual("ts2", ts2.key) self.assertEqual(1.1, float(ts1)) self.assertEqual(1.1, float(ts2))
def test_immutable(self): ts = rom.Timestamp(connection=self.conn, key="ts") value = ts.setnx() self.assertEqual(value, ts.value) self.assertRaises(ValueError, setattr, ts, 'value', 12.3) self.assertEqual(value, ts.value)
def test_setter(self): ts = rom.Timestamp(self.conn, "ts") self.assertRaises(ValueError, setattr, ts, 'value', 'DUMMY')
def test_setnx_succeed(self): ts = rom.Timestamp(self.conn, "ts") rv = ts.setnx(1.23) self.assertEqual(1.23, rv) self.assertEqual(1.23, ts.value)
def test_uninitialized(self): ts = rom.Timestamp(self.conn, "ts") self.assertRaises(rom.NotInRedisError, getattr, ts, "value")