1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

Fixed #26977 -- Made abstract models raise TypeError when instantiating.

This commit is contained in:
Jacob Walls
2020-08-02 16:20:30 -04:00
committed by Mariusz Felisiak
parent 6c19230297
commit c7e7f176c1
4 changed files with 19 additions and 7 deletions

View File

@@ -279,10 +279,19 @@ class ParentListTests(SimpleTestCase):
class PropertyNamesTests(SimpleTestCase):
def test_person(self):
# Instance only descriptors don't appear in _property_names.
self.assertEqual(AbstractPerson().test_instance_only_descriptor, 1)
self.assertEqual(BasePerson().test_instance_only_descriptor, 1)
with self.assertRaisesMessage(AttributeError, 'Instance only'):
AbstractPerson.test_instance_only_descriptor
self.assertEqual(AbstractPerson._meta._property_names, frozenset(['pk', 'test_property']))
class ReturningFieldsTests(SimpleTestCase):
def test_pk(self):
self.assertEqual(Relation._meta.db_returning_fields, [Relation._meta.pk])
class AbstractModelTests(SimpleTestCase):
def test_abstract_model_not_instantiated(self):
msg = 'Abstract models cannot be instantiated.'
with self.assertRaisesMessage(TypeError, msg):
AbstractPerson()