mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	This reduces duplication by allowing AutoField, BigAutoField and SmallAutoField to inherit from IntegerField, BigIntegerField and SmallIntegerField respectively. Doing so also allows for enabling the max_length warning check and minimum/maximum value validation for auto fields, as well as providing a mixin that can be used for other possible future auto field types such as a theoretical UUIDAutoField.
		
			
				
	
	
		
			33 lines
		
	
	
		
			955 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			33 lines
		
	
	
		
			955 B
		
	
	
	
		
			Python
		
	
	
	
	
	
| from django.db import models
 | |
| from django.test import SimpleTestCase
 | |
| 
 | |
| from .models import AutoModel, BigAutoModel, SmallAutoModel
 | |
| from .test_integerfield import (
 | |
|     BigIntegerFieldTests, IntegerFieldTests, SmallIntegerFieldTests,
 | |
| )
 | |
| 
 | |
| 
 | |
| class AutoFieldTests(IntegerFieldTests):
 | |
|     model = AutoModel
 | |
| 
 | |
| 
 | |
| class BigAutoFieldTests(BigIntegerFieldTests):
 | |
|     model = BigAutoModel
 | |
| 
 | |
| 
 | |
| class SmallAutoFieldTests(SmallIntegerFieldTests):
 | |
|     model = SmallAutoModel
 | |
| 
 | |
| 
 | |
| class AutoFieldInheritanceTests(SimpleTestCase):
 | |
| 
 | |
|     def test_isinstance_of_autofield(self):
 | |
|         for field in (models.BigAutoField, models.SmallAutoField):
 | |
|             with self.subTest(field.__name__):
 | |
|                 self.assertIsInstance(field(), models.AutoField)
 | |
| 
 | |
|     def test_issubclass_of_autofield(self):
 | |
|         for field in (models.BigAutoField, models.SmallAutoField):
 | |
|             with self.subTest(field.__name__):
 | |
|                 self.assertTrue(issubclass(field, models.AutoField))
 |