2011-12-15 10:33:14 +08:00
|
|
|
import pickle
|
2010-09-27 23:15:04 +08:00
|
|
|
|
2013-09-18 21:35:51 +08:00
|
|
|
from django.contrib.auth.models import User
|
2014-01-29 12:53:30 +08:00
|
|
|
from django.test import TestCase
|
|
|
|
from django.utils.functional import SimpleLazyObject
|
2011-06-01 23:30:06 +08:00
|
|
|
|
2010-09-27 23:15:04 +08:00
|
|
|
|
2014-01-29 12:53:30 +08:00
|
|
|
class TestUtilsSimpleLazyObjectDjangoTestCase(TestCase):
|
2017-01-22 09:02:00 +08:00
|
|
|
def test_pickle(self):
|
2013-05-21 13:17:56 +08:00
|
|
|
user = User.objects.create_user("johndoe", "john@example.com", "pass")
|
|
|
|
x = SimpleLazyObject(lambda: user)
|
2013-10-19 20:31:38 +08:00
|
|
|
pickle.dumps(x)
|
2013-05-21 13:17:56 +08:00
|
|
|
# Try the variant protocol levels.
|
2013-10-19 20:31:38 +08:00
|
|
|
pickle.dumps(x, 0)
|
|
|
|
pickle.dumps(x, 1)
|
|
|
|
pickle.dumps(x, 2)
|