示例#1
0
文件: tests.py 项目: yellowcap/django
 def test_add_field_temp_default_boolean(self):
     """
     Tests adding fields to models with a temporary default where
     the default is False. (#21783)
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure there's no age field
     columns = self.column_classes(Author)
     self.assertNotIn("age", columns)
     # Add some rows of data
     Author.objects.create(name="Andrew", height=30)
     Author.objects.create(name="Andrea")
     # Add a not-null field
     new_field = BooleanField(default=False)
     new_field.set_attributes_from_name("awesome")
     with connection.schema_editor() as editor:
         editor.add_field(
             Author,
             new_field,
         )
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     # BooleanField are stored as TINYINT(1) on MySQL.
     field_type = columns['awesome'][0]
     self.assertEqual(
         field_type,
         connection.features.introspected_boolean_field_type(
             new_field, created_separately=True))
示例#2
0
 def test_add_field_temp_default_boolean(self):
     """
     Tests adding fields to models with a temporary default where
     the default is False. (#21783)
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure there's no age field
     columns = self.column_classes(Author)
     self.assertNotIn("age", columns)
     # Add some rows of data
     Author.objects.create(name="Andrew", height=30)
     Author.objects.create(name="Andrea")
     # Add a not-null field
     new_field = BooleanField(default=False)
     new_field.set_attributes_from_name("awesome")
     with connection.schema_editor() as editor:
         editor.add_field(
             Author,
             new_field,
         )
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     # BooleanField are stored as TINYINT(1) on MySQL.
     field_type = columns['awesome'][0]
     self.assertEqual(field_type, connection.features.introspected_boolean_field_type(new_field, created_separately=True))
示例#3
0
 def test_add_field_temp_default_boolean(self):
     """
     Tests adding fields to models with a temporary default where
     the default is False. (#21783)
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure there's no age field
     columns = self.column_classes(Author)
     self.assertNotIn("age", columns)
     # Add some rows of data
     Author.objects.create(name="Andrew", height=30)
     Author.objects.create(name="Andrea")
     # Add a not-null field
     new_field = BooleanField(default=False)
     new_field.set_attributes_from_name("awesome")
     with connection.schema_editor() as editor:
         editor.add_field(
             Author,
             new_field,
         )
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     # BooleanField are stored as TINYINT(1) on MySQL.
     field_type, field_info = columns['awesome']
     if connection.vendor == 'mysql':
         self.assertEqual(field_type, 'IntegerField')
         self.assertEqual(field_info.precision, 1)
     elif connection.vendor == 'oracle' and connection.version_has_default_introspection_bug:
         self.assertEqual(field_type, 'IntegerField')
         self.assertEqual(field_info.precision, 0)
     else:
         self.assertEqual(field_type, 'BooleanField')
示例#4
0
文件: tests.py 项目: 6ft/django
 def test_add_field_temp_default_boolean(self):
     """
     Tests adding fields to models with a temporary default where
     the default is False. (#21783)
     """
     # Create the table
     with connection.schema_editor() as editor:
         editor.create_model(Author)
     # Ensure there's no age field
     columns = self.column_classes(Author)
     self.assertNotIn("age", columns)
     # Add some rows of data
     Author.objects.create(name="Andrew", height=30)
     Author.objects.create(name="Andrea")
     # Add a not-null field
     new_field = BooleanField(default=False)
     new_field.set_attributes_from_name("awesome")
     with connection.schema_editor() as editor:
         editor.add_field(
             Author,
             new_field,
         )
     # Ensure the field is right afterwards
     columns = self.column_classes(Author)
     # BooleanField are stored as TINYINT(1) on MySQL.
     field_type, field_info = columns['awesome']
     if connection.vendor == 'mysql':
         self.assertEqual(field_type, 'IntegerField')
         self.assertEqual(field_info.precision, 1)
     else:
         self.assertEqual(field_type, 'BooleanField')