issue #218: core: add Secret and Blob types.
parent
be5c03c152
commit
cecef992b0
@ -0,0 +1,72 @@
|
||||
|
||||
import cStringIO
|
||||
|
||||
import unittest2
|
||||
|
||||
import mitogen.core
|
||||
|
||||
|
||||
class BlobTest(unittest2.TestCase):
|
||||
klass = mitogen.core.Blob
|
||||
|
||||
def make(self):
|
||||
return self.klass('x' * 128)
|
||||
|
||||
def test_repr(self):
|
||||
blob = self.make()
|
||||
self.assertEquals('[blob: 128 bytes]', repr(blob))
|
||||
|
||||
def test_decays_on_constructor(self):
|
||||
blob = self.make()
|
||||
self.assertEquals('x'*128, mitogen.core.BytesType(blob))
|
||||
|
||||
def test_decays_on_write(self):
|
||||
blob = self.make()
|
||||
io = cStringIO.StringIO()
|
||||
io.write(blob)
|
||||
self.assertEquals(128, io.tell())
|
||||
self.assertEquals('x'*128, io.getvalue())
|
||||
|
||||
def test_message_roundtrip(self):
|
||||
blob = self.make()
|
||||
msg = mitogen.core.Message.pickled(blob)
|
||||
blob2 = msg.unpickle()
|
||||
self.assertEquals(type(blob), type(blob2))
|
||||
self.assertEquals(repr(blob), repr(blob2))
|
||||
self.assertEquals(mitogen.core.BytesType(blob),
|
||||
mitogen.core.BytesType(blob2))
|
||||
|
||||
|
||||
class SecretTest(unittest2.TestCase):
|
||||
klass = mitogen.core.Secret
|
||||
|
||||
def make(self):
|
||||
return self.klass('password')
|
||||
|
||||
def test_repr(self):
|
||||
secret = self.make()
|
||||
self.assertEquals('[secret]', repr(secret))
|
||||
|
||||
def test_decays_on_constructor(self):
|
||||
secret = self.make()
|
||||
self.assertEquals('password', mitogen.core.UnicodeType(secret))
|
||||
|
||||
def test_decays_on_write(self):
|
||||
secret = self.make()
|
||||
io = cStringIO.StringIO()
|
||||
io.write(secret)
|
||||
self.assertEquals(8, io.tell())
|
||||
self.assertEquals('password', io.getvalue())
|
||||
|
||||
def test_message_roundtrip(self):
|
||||
secret = self.make()
|
||||
msg = mitogen.core.Message.pickled(secret)
|
||||
secret2 = msg.unpickle()
|
||||
self.assertEquals(type(secret), type(secret2))
|
||||
self.assertEquals(repr(secret), repr(secret2))
|
||||
self.assertEquals(mitogen.core.BytesType(secret),
|
||||
mitogen.core.BytesType(secret2))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest2.main()
|
Loading…
Reference in New Issue