21
21
import pickle
22
22
import unittest
23
23
24
+ import jsonpickle
25
+
24
26
from oauth2client import _helpers
25
27
from oauth2client import client
26
28
from oauth2client .contrib .django_util import models
@@ -36,6 +38,8 @@ def setUp(self):
36
38
self .credentials = client .Credentials ()
37
39
self .pickle_str = _helpers ._from_bytes (
38
40
base64 .b64encode (pickle .dumps (self .credentials )))
41
+ self .jsonpickle_str = _helpers ._from_bytes (
42
+ base64 .b64encode (jsonpickle .encode (self .credentials ).encode ()))
39
43
40
44
def test_field_is_text (self ):
41
45
self .assertEqual (self .field .get_internal_type (), 'BinaryField' )
@@ -44,6 +48,10 @@ def test_field_unpickled(self):
44
48
self .assertIsInstance (
45
49
self .field .to_python (self .pickle_str ), client .Credentials )
46
50
51
+ def test_field_jsonunpickled (self ):
52
+ self .assertIsInstance (
53
+ self .field .to_python (self .jsonpickle_str ), client .Credentials )
54
+
47
55
def test_field_already_unpickled (self ):
48
56
self .assertIsInstance (
49
57
self .field .to_python (self .credentials ), client .Credentials )
@@ -62,12 +70,12 @@ def test_field_unpickled_none(self):
62
70
def test_field_pickled (self ):
63
71
prep_value = self .field .get_db_prep_value (self .credentials ,
64
72
connection = None )
65
- self .assertEqual (prep_value , self .pickle_str )
73
+ self .assertEqual (prep_value , self .jsonpickle_str )
66
74
67
75
def test_field_value_to_string (self ):
68
76
self .fake_model .credentials = self .credentials
69
77
value_str = self .fake_model_field .value_to_string (self .fake_model )
70
- self .assertEqual (value_str , self .pickle_str )
78
+ self .assertEqual (value_str , self .jsonpickle_str )
71
79
72
80
def test_field_value_to_string_none (self ):
73
81
self .fake_model .credentials = None
0 commit comments