django 1.10 fix (#516)

Fix django packages for 1.10, add docs noting django 1.8+ support.
This commit is contained in:
Bill Prin
2016-06-06 12:42:18 -07:00
committed by Jon Wayne Parrott
parent f322ef9cdf
commit a3cbf51bc9
3 changed files with 38 additions and 4 deletions

View File

@@ -16,6 +16,9 @@
Utilities for using OAuth 2.0 in conjunction with
the Django datastore.
Only Django versions 1.8+ are supported.
"""
import oauth2client
@@ -31,7 +34,7 @@ from oauth2client.client import Storage as BaseStorage
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
class CredentialsField(models.Field):
def __init__(self, *args, **kwargs):
if 'null' not in kwargs:
@@ -41,6 +44,9 @@ class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
def get_internal_type(self):
return 'TextField'
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)
def to_python(self, value):
if value is None:
return None
@@ -68,7 +74,7 @@ class CredentialsField(six.with_metaclass(models.SubfieldBase, models.Field)):
return self.get_prep_value(value)
class FlowField(six.with_metaclass(models.SubfieldBase, models.Field)):
class FlowField(models.Field):
def __init__(self, *args, **kwargs):
if 'null' not in kwargs:
@@ -78,6 +84,9 @@ class FlowField(six.with_metaclass(models.SubfieldBase, models.Field)):
def get_internal_type(self):
return 'TextField'
def from_db_value(self, value, expression, connection, context):
return self.to_python(value)
def to_python(self, value):
if value is None:
return None

View File

@@ -20,6 +20,7 @@ that user credentials are available, and an ``oauth_enabled`` decorator to check
if the user has authorized, and helper shortcuts to create the authorization
URL otherwise.
Only Django versions 1.8+ are supported.
Configuration
=============

View File

@@ -74,8 +74,20 @@ class TestCredentialsField(unittest.TestCase):
self.assertEquals(self.field.get_internal_type(), 'TextField')
def test_field_unpickled(self):
self.assertTrue(isinstance(self.field.to_python(self.pickle_str),
Credentials))
self.assertTrue(
isinstance(self.field.to_python(self.pickle_str), Credentials))
def test_field_already_unpickled(self):
self.assertTrue(isinstance(
self.field.to_python(self.credentials), Credentials))
def test_none_field_unpickled(self):
self.assertIsNone(self.field.to_python(None))
def test_from_db_value(self):
value = self.field.from_db_value(
self.pickle_str, None, None, None)
self.assertTrue(isinstance(value, Credentials))
def test_field_unpickled_none(self):
self.assertEqual(self.field.to_python(None), None)
@@ -120,6 +132,18 @@ class TestFlowField(unittest.TestCase):
python_val = self.field.to_python(self.pickle_str)
self.assertTrue(isinstance(python_val, Flow))
def test_field_already_unpickled(self):
self.assertTrue(
isinstance(self.field.to_python(self.flow), Flow))
def test_none_field_unpickled(self):
self.assertIsNone(self.field.to_python(None))
def test_from_db_value(self):
python_val = self.field.from_db_value(
self.pickle_str, None, None, None)
self.assertTrue(isinstance(python_val, Flow))
def test_field_pickled(self):
prep_value = self.field.get_db_prep_value(self.flow, connection=None)
self.assertEqual(prep_value, self.pickle_str)