Make django_orm models use TEXT instead of VARCHAR.

Reviewed in http://codereview.appspot.com/5165047/
diff --git a/oauth2client/django_orm.py b/oauth2client/django_orm.py
index 5e511db..d3642f7 100644
--- a/oauth2client/django_orm.py
+++ b/oauth2client/django_orm.py
@@ -31,8 +31,8 @@
 
   __metaclass__ = models.SubfieldBase
 
-  def db_type(self, connection=None):
-    return 'VARCHAR'
+  def get_internal_type(self):
+    return "TextField"
 
   def to_python(self, value):
     if not value:
@@ -41,7 +41,7 @@
       return value
     return pickle.loads(base64.b64decode(value))
 
-  def get_db_prep_value(self, value):
+  def get_db_prep_value(self, value, connection, prepared=False):
     return base64.b64encode(pickle.dumps(value))
 
 
@@ -49,8 +49,8 @@
 
   __metaclass__ = models.SubfieldBase
 
-  def db_type(self, connection=None):
-    return 'VARCHAR'
+  def get_internal_type(self):
+    return "TextField"
 
   def to_python(self, value):
     if value is None:
@@ -59,7 +59,7 @@
       return value
     return pickle.loads(base64.b64decode(value))
 
-  def get_db_prep_value(self, value):
+  def get_db_prep_value(self, value, connection, prepared=False):
     return base64.b64encode(pickle.dumps(value))
 
 
diff --git a/runtests.py b/runtests.py
index a09a6c0..c1f9d1d 100644
--- a/runtests.py
+++ b/runtests.py
@@ -19,6 +19,10 @@
 sys.path.insert(0, os.getcwd())
 sys.path.insert(0, APP_ENGINE_PATH)
 
+from google.appengine.dist import use_library
+use_library('django', '1.2')
+
+
 def build_suite(folder, verbosity):
   # find all of the test modules
   top_level_modules = map(fullmodname, glob.glob(os.path.join(folder, 'test_*.py')))
diff --git a/tests/test_oauth2client_django_orm.py b/tests/test_oauth2client_django_orm.py
new file mode 100644
index 0000000..67ec314
--- /dev/null
+++ b/tests/test_oauth2client_django_orm.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2011 Google Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+"""Discovery document tests
+
+Unit tests for objects created from discovery documents.
+"""
+
+__author__ = 'conleyo@google.com (Conley Owens)'
+
+import base64
+import imp
+import os
+import pickle
+import sys
+import unittest
+
+from oauth2client.client import Credentials
+from oauth2client.client import Flow
+
+# Mock a Django environment
+os.environ['DJANGO_SETTINGS_MODULE'] = 'django_settings'
+sys.modules['django_settings'] = imp.new_module('django_settings')
+
+from oauth2client.django_orm import CredentialsField
+from oauth2client.django_orm import FlowField
+
+
+class TestCredentialsField(unittest.TestCase):
+  def setUp(self):
+    self.field = CredentialsField()
+    self.credentials = Credentials()
+    self.pickle = base64.b64encode(pickle.dumps(self.credentials))
+
+  def test_field_is_text(self):
+    self.assertEquals(self.field.get_internal_type(), 'TextField')
+
+  def test_field_unpickled(self):
+    self.assertTrue(isinstance(self.field.to_python(self.pickle), Credentials))
+
+  def test_field_pickled(self):
+    prep_value = self.field.get_db_prep_value(self.credentials,
+                                              connection=None)
+    self.assertEqual(prep_value, self.pickle)
+
+
+class TestFlowField(unittest.TestCase):
+  def setUp(self):
+    self.field = FlowField()
+    self.flow = Flow()
+    self.pickle = base64.b64encode(pickle.dumps(self.flow))
+
+  def test_field_is_text(self):
+    self.assertEquals(self.field.get_internal_type(), 'TextField')
+
+  def test_field_unpickled(self):
+    self.assertTrue(isinstance(self.field.to_python(self.pickle), Flow))
+
+  def test_field_pickled(self):
+    prep_value = self.field.get_db_prep_value(self.flow, connection=None)
+    self.assertEqual(prep_value, self.pickle)