Example #1
0
 def test_encode_passed_Header(self):
     d = datetime.strptime('1990-04-27', '%Y-%m-%d')
     h = (Header().set_id('12345').set_username('senkwich').set_session(
         'mysession').set_date(d).set_type('some_type').set_version('1.0'))
     o = Header.encode(h)
     assert o[Header.name()]
     assert o['_id'] == h.get_id()
     assert o['_username'] == h.get_username()
     assert o['_session'] == h.get_session()
     assert o['_date'] == h.get_date()
     assert o['_type'] == h.get_type()
     assert o['_version'] == h.get_version()
Example #2
0
    def test_decode_passed_encoded_Header(self):
        d = datetime.strptime('1990-04-27', '%Y-%m-%d')
        h = (Header().set_id('12345').set_username('senkwich').set_session(
            'mysession').set_date(d).set_type('some_type').set_version('1.0'))

        encoded = {}
        encoded[Header.name()] = True
        encoded['_id'] = h.get_id()
        encoded['_username'] = h.get_username()
        encoded['_session'] = h.get_session()
        encoded['_date'] = h.get_date()
        encoded['_type'] = h.get_type()
        encoded['_version'] = h.get_version()

        new_h = Header.decode(encoded)
        assert new_h.to_dict() == h.to_dict()
Example #3
0
    def test_to_bytes_everything_already_set(self):
        d = datetime.strptime('1990-04-27', '%Y-%m-%d')
        h = (Header().set_id('12345').set_username('senkwich').set_session(
            'mysession').set_date(d).set_type('some_type').set_version('1.0'))

        b = h.to_bytes()

        expected = {}
        expected[Header.name()] = True
        expected['_id'] = h.get_id()
        expected['_username'] = h.get_username()
        expected['_session'] = h.get_session()
        expected['_date'] = {
            '__datetime__': True,
            's': d.strftime('%Y%m%dT%H:%M:%S.%f'),
        }
        expected['_type'] = h.get_type()
        expected['_version'] = h.get_version()
        expected = msgpack.packb(expected, use_bin_type=True)

        assert b == expected