Skip to content

Commit

Permalink
Fixed TestSchemaMode in django 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Jun 7, 2015
1 parent c71d09b commit 25fdb40
Showing 1 changed file with 86 additions and 43 deletions.
129 changes: 86 additions & 43 deletions tests/django_hstore_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ def test_str(self):
self.assertEqual(str(d.data), '{}')


class SchemaTests(TestCase):
class TestSchemaMode(TestCase):
if DJANGO_VERSION[:2] >= (1, 6):
@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -1472,47 +1472,90 @@ def test_str(self):
d = SchemaDataBag()
self.assertEqual(str(d.data), '{}')

def test_reload_schema(self):
# cache some stuff
f = SchemaDataBag._meta.get_field('data')
original_schema = list(f.schema)
concrete_fields_length = len(SchemaDataBag._meta.concrete_fields)
hstore_virtual_fields_keys = list(SchemaDataBag._hstore_virtual_fields.keys())

# original state
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + concrete_fields_length)
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))

# schema erased
f.reload_schema(None)
self.assertIsNone(f.schema)
self.assertFalse(f.schema_mode)
self.assertTrue(f.editable)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), 0)
self.assertEqual(len(SchemaDataBag._meta.fields), concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), concrete_fields_length)
self.assertFalse(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
d = SchemaDataBag()
self.assertFalse(d.data.schema_mode)
for key in hstore_virtual_fields_keys:
self.assertFalse(hasattr(d, key))

# reload original schema
f.reload_schema(original_schema)
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + concrete_fields_length)
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))
if DJANGO_VERSION[:2] >= (1, 8):
def test_reload_schema(self):
# cache some stuff
f = SchemaDataBag._meta.get_field('data')
original_schema = list(f.schema)
local_fields_length = len(SchemaDataBag._meta.local_fields)
hstore_virtual_fields_keys = list(SchemaDataBag._hstore_virtual_fields.keys())

# original state
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + local_fields_length)
#self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + local_fields_length)
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))

# schema erased
f.reload_schema(None)
self.assertIsNone(f.schema)
self.assertFalse(f.schema_mode)
self.assertTrue(f.editable)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), 0)
#self.assertEqual(len(SchemaDataBag._meta.fields), local_fields_length)
#self.assertEqual(len(SchemaDataBag._meta.local_fields), local_fields_length)
#self.assertFalse(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
d = SchemaDataBag()
self.assertFalse(d.data.schema_mode)
for key in hstore_virtual_fields_keys:
self.assertFalse(hasattr(d, key))

# reload original schema
f.reload_schema(original_schema)
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
#self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
#self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + local_fields_length)
#self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + local_fields_length)
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))
else:
def test_reload_schema(self):
# cache some stuff
f = SchemaDataBag._meta.get_field('data')
original_schema = list(f.schema)
concrete_fields_length = len(SchemaDataBag._meta.concrete_fields)
hstore_virtual_fields_keys = list(SchemaDataBag._hstore_virtual_fields.keys())

# original state
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + concrete_fields_length)
self.assertTrue(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
for key in hstore_virtual_fields_keys:
self.assertTrue(hasattr(d, key))

# schema erased
f.reload_schema(None)
self.assertIsNone(f.schema)
self.assertFalse(f.schema_mode)
self.assertTrue(f.editable)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), 0)
self.assertEqual(len(SchemaDataBag._meta.fields), concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), concrete_fields_length)
self.assertFalse(hasattr(SchemaDataBag, '_hstore_virtual_fields'))
d = SchemaDataBag()
self.assertFalse(d.data.schema_mode)
for key in hstore_virtual_fields_keys:
self.assertFalse(hasattr(d, key))

# reload original schema
f.reload_schema(original_schema)
d = SchemaDataBag()
self.assertTrue(d.data.schema_mode)
self.assertEqual(len(SchemaDataBag._meta.virtual_fields), len(original_schema))
self.assertEqual(len(SchemaDataBag._meta.fields), len(original_schema) + concrete_fields_length)
self.assertEqual(len(SchemaDataBag._meta.local_fields), len(original_schema) + concrete_fields_length)
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 """
Expand Down Expand Up @@ -1576,7 +1619,7 @@ class Migration(migrations.Migration):
# start capturing output
output = StringIO()
sys.stdout = output
call_command('migrate', 'django_hstore_tests')
call_command('migrate', 'django_hstore_tests', fake_initial=True)
# stop capturing print statements
sys.stdout = sys.__stdout__
self.assertIn('Applying django_hstore_tests.0002_issue_103... OK', output.getvalue())
Expand Down

0 comments on commit 25fdb40

Please sign in to comment.