From 7c676a9f4ec69a60c3124a8a6c43d684d5126c81 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Tue, 17 Mar 2015 14:30:37 +0100 Subject: [PATCH] Added test case for #82, wrong DateTimeField default value in schema mode --- tests/django_hstore_tests/models.py | 11 ++++----- tests/django_hstore_tests/tests.py | 35 +++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/tests/django_hstore_tests/models.py b/tests/django_hstore_tests/models.py index 5f53710..16aadbd 100755 --- a/tests/django_hstore_tests/models.py +++ b/tests/django_hstore_tests/models.py @@ -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") @@ -155,7 +155,8 @@ class SchemaDataBag(HStoreModel): 'name': 'datetime', 'class': 'DateTimeField', 'kwargs': { - 'blank': True + 'blank': True, + 'null': True } }, { @@ -190,7 +191,7 @@ class SchemaDataBag(HStoreModel): } }, ]) - + __all__.append('SchemaDataBag') @@ -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') diff --git a/tests/django_hstore_tests/tests.py b/tests/django_hstore_tests/tests.py index 0d614b1..87a4319 100755 --- a/tests/django_hstore_tests/tests.py +++ b/tests/django_hstore_tests/tests.py @@ -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):