File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818from collections import OrderedDict
1919import datetime
2020
21+ import six
22+
2123from google .cloud ._helpers import _date_from_iso8601_date
2224from google .cloud ._helpers import _datetime_from_microseconds
2325from google .cloud ._helpers import _datetime_to_rfc3339
2426from google .cloud ._helpers import _microseconds_from_datetime
2527from google .cloud ._helpers import _RFC3339_NO_FRACTION
2628from google .cloud ._helpers import _time_from_iso8601_time_naive
29+ from google .cloud ._helpers import _to_bytes
2730
2831
2932def _not_null (value , field ):
@@ -57,7 +60,8 @@ def _string_from_json(value, _):
5760def _bytes_from_json (value , field ):
5861 """Base64-decode value"""
5962 if _not_null (value , field ):
60- return base64 .decodestring (value )
63+ return base64 .decodestring (
64+ _to_bytes (value ) if isinstance (value , six .text_type ) else value )
6165
6266
6367def _timestamp_from_json (value , field ):
Original file line number Diff line number Diff line change @@ -135,13 +135,20 @@ def test_w_none_required(self):
135135 with self .assertRaises (TypeError ):
136136 self ._call_fut (None , _Field ('REQUIRED' ))
137137
138- def test_w_base64_encoded_value (self ):
138+ def test_w_base64_encoded_bytes (self ):
139139 import base64
140140 expected = b'Wonderful!'
141141 encoded = base64 .encodestring (expected )
142142 coerced = self ._call_fut (encoded , object ())
143143 self .assertEqual (coerced , expected )
144144
145+ def test_w_base64_encoded_text (self ):
146+ import base64
147+ expected = b'Wonderful!'
148+ encoded = base64 .encodestring (expected ).decode ('ascii' )
149+ coerced = self ._call_fut (encoded , object ())
150+ self .assertEqual (coerced , expected )
151+
145152
146153class Test_timestamp_from_json (unittest .TestCase ):
147154
You can’t perform that action at this time.
0 commit comments