Waldemar Kornewald avatar Waldemar Kornewald committed f5cd0bf

added a test for BlobModel

Comments (0)

Files changed (3)

tests/field_options.py

 
         time = datetime.datetime.now().time()
         entity.time = time
-        try:
-            entity.save()
-        except:
-            self.fail()
+        entity.save()
 
-        # check if primary_key=True is set correct for the saved entity
+        # check if primary_key=True is set correctly for the saved entity
         self.assertEquals(entity.pk, u'app-engine@scholardocs.com')
         gae_entity = Get(Key.from_path(FieldsWithOptionsModel._meta.db_table,
             entity.pk))
         self.assertTrue(gae_entity is not None)
         self.assertEquals(gae_entity.key().name(), u'app-engine@scholardocs.com')
         
-        # check if default values are set correct on the db level, primary_key field
-        # is not stored at the db level
+        # check if default values are set correctly on the db level,
+        # primary_key field is not stored at the db level
         for field in FieldsWithOptionsModel._meta.local_fields:
             if field.default and field.default != NOT_PROVIDED and not \
                     field.primary_key:
             elif field.column == 'time':
                 self.assertEquals(gae_entity[field.column], datetime.datetime(
                     1970, 1, 1, time.hour, time.minute, time.second, time.microsecond))
-            elif field.null:
+            elif field.null and field.editable:
                 self.assertEquals(gae_entity[field.column], None)
 
         # check if default values are set correct on the model instance level
                 self.assertEquals(getattr(entity, field.column), field.default)
             elif field.column == 'time':
                 self.assertEquals(getattr(entity, field.column), time)
-            elif field.null:
+            elif field.null and field.editable:
                 self.assertEquals(getattr(entity, field.column), None)
 
         # check if nullable field with default values can be set to None
 from django.db.models import Q
 from django.db.utils import DatabaseError
 from djangoappengine.db.utils import set_cursor
+from djangoappengine.tests.testmodels import BlobModel
+from google.appengine.api.datastore import Get, Key
 
 class FilterTest(TestCase):
     floats = [5.3, 2.6, 9.1, 1.58]
                           email='rinnengan@sage.de').order_by('email')],
                           ['rinnengan@sage.de'])
 
-        # test using exact
-        self.assertEquals(FieldsWithOptionsModel.objects.filter(
-                          email__exact='rinnengan@sage.de')[0].email,
-                          'rinnengan@sage.de')
-
-        self.assertEquals(FieldsWithOptionsModel.objects.filter(
-                           pk='app-engine@scholardocs.com')[0].email,
-                          'app-engine@scholardocs.com')
-
     def test_is_null(self):
         self.assertEquals(FieldsWithOptionsModel.objects.filter(
             floating_point__isnull=True).count(), 0)
     def test_latest(self):
         self.assertEquals(FieldsWithOptionsModel.objects.latest('time').floating_point,
                             1.58)
+
+    def test_blob(self):
+        x = BlobModel(data='lalala')
+        x.full_clean()
+        x.save()
+        e = Get(Key.from_path(BlobModel._meta.db_table, x.pk))
+        self.assertEqual(e['data'], x.data)
+        x = BlobModel.objects.all()[0]
+        self.assertEqual(e['data'], x.data)

tests/testmodels.py

 from django.db import models
 from ..db.db_settings import get_indexes
+from djangotoolbox.fields import BlobField
 
 class EmailModel(models.Model):
     email = models.EmailField()
     class Meta:
         ordering = ('-priority',)
 
+class BlobModel(models.Model):
+    data = BlobField()
+
 class DecimalModel(models.Model):
     decimal = models.DecimalField(max_digits=9, decimal_places=2)
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.