()
| 104 | |
| 105 | |
| 106 | def test_bytes_base64(): |
| 107 | s = SchemaSerializer(core_schema.bytes_schema(), {'ser_json_bytes': 'base64'}) |
| 108 | assert s.to_python(b'foobar') == b'foobar' |
| 109 | |
| 110 | assert s.to_json(b'foobar') == b'"Zm9vYmFy"' |
| 111 | assert s.to_python(b'foobar', mode='json') == 'Zm9vYmFy' |
| 112 | assert base64.b64decode(s.to_python(b'foobar', mode='json').encode()) == b'foobar' |
| 113 | |
| 114 | # with padding |
| 115 | assert s.to_json(b'foo bar') == b'"Zm9vIGJhcg=="' |
| 116 | assert s.to_python(b'foo bar', mode='json') == 'Zm9vIGJhcg==' |
| 117 | assert base64.b64decode(s.to_python(b'foo bar', mode='json').encode()) == b'foo bar' |
| 118 | |
| 119 | |
| 120 | def test_bytes_hex(): |
nothing calls this directly
no test coverage detected