Skip to content

Commit

Permalink
Added test case for #82, wrong DateTimeField default value in schema …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
nemesifier committed Mar 17, 2015
1 parent 7563487 commit 7c676a9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
11 changes: 6 additions & 5 deletions tests/django_hstore_tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class NumberedDataBag(HStoreModel):
class UniqueTogetherDataBag(HStoreModel):
name = models.CharField(max_length=32)
data = hstore.DictionaryField()

class Meta:
unique_together = ("name", "data")

Expand Down Expand Up @@ -155,7 +155,8 @@ class SchemaDataBag(HStoreModel):
'name': 'datetime',
'class': 'DateTimeField',
'kwargs': {
'blank': True
'blank': True,
'null': True
}
},
{
Expand Down Expand Up @@ -190,7 +191,7 @@ class SchemaDataBag(HStoreModel):
}
},
])

__all__.append('SchemaDataBag')


Expand All @@ -201,7 +202,7 @@ class Location(geo_models.Model):
name = geo_models.CharField(max_length=32)
data = hstore.DictionaryField()
point = geo_models.GeometryField()

objects = hstore.HStoreGeoManager()

__all__.append('Location')
35 changes: 35 additions & 0 deletions tests/django_hstore_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,41 @@ def test_reload_schema(self):
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))

def test_datetime_is_none(self):
""" issue #82 https://github.com/djangonauts/django-hstore/issues/82 """
d = SchemaDataBag()
d.name = 'datetime'
self.assertIsNone(d.datetime, None)
d.full_clean()
d.save()
d = SchemaDataBag.objects.get(name='datetime')
self.assertIsNone(d.datetime, None)

def test_migration_datetime(self):
""" issue #82 https://github.com/djangonauts/django-hstore/issues/82 """
from django.core.management import call_command
from cStringIO import StringIO
# start capturing output
output = StringIO()
sys.stdout = output
call_command('makemigrations', 'django_hstore_tests')
# stop capturing print statements
sys.stdout = sys.__stdout__
self.assertIn('0001_initial', output.getvalue())
# check migration file
path = './django_hstore_tests/migrations'
filename = '0001_initial.py'
try:
migration_file = open('{0}/{1}'.format(path, filename))
except IOError:
path = path.replace('./', './tests/')
migration_file = open('{0}/{1}'.format(path, filename))
self.assertNotIn("('datetime', django_hstore.virtual.VirtualField(default=datetime.datetime", migration_file.read())
# delete migration files
import shutil
shutil.rmtree(path)

else:
def test_improperly_configured(self):
with self.assertRaises(ImproperlyConfigured):
Expand Down

0 comments on commit 7c676a9

Please sign in to comment.