def test_decimal(self): obj = {'my_date': decimal.Decimal(1) / decimal.Decimal(7)} renderer = MessagePackRenderer() parser = MessagePackParser() content = renderer.render(obj, 'application/msgpack') data = parser.parse(BytesIO(content)) self.assertEquals(obj, data)
def test_time(self): obj = {'my_date': datetime.datetime.now().time()} renderer = MessagePackRenderer() parser = MessagePackParser() content = renderer.render(obj, 'application/msgpack') data = parser.parse(BytesIO(content)) self.assertEquals(obj, data)
def test_date(self): obj = {'my_date': datetime.date.today()} renderer = MessagePackRenderer() parser = MessagePackParser() content = renderer.render(obj, 'application/msgpack') data = parser.parse(StringIO(content)) self.assertEquals(obj, data)
def test_render_and_parse(self): """ Test rendering and then parsing returns the original object. IE obj -> render -> parse -> obj. """ obj = {'foo': ['bar', {'baz': [1, 2]}]} renderer = MessagePackRenderer() parser = MessagePackParser() content = renderer.render(obj, 'application/msgpack') data = parser.parse(BytesIO(content)) self.assertEquals(obj, data)
def test_handle_invalid_payload(self): invalid_msgpack_repr = b'\xa1\xa3foo\x92\xa3bar\xa4baz' parser = MessagePackParser() with self.assertRaises(ParseError): parser.parse(invalid_msgpack_repr)