diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-04-15 12:18:08 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2019-04-24 09:59:09 +0200 |
| commit | 607ff4efa31cd0c2217ed021dc939ffddad89c97 (patch) | |
| tree | 8bcadfd7bd6f667c55706db8481494b07bac185e /tests/basic | |
| parent | c00b4dbda2d9217cac205c4ffb3ccc1fa59a28ae (diff) | |
Refs #30254 -- Added tests for Model.__hash__() inheritance.
Diffstat (limited to 'tests/basic')
| -rw-r--r-- | tests/basic/tests.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/tests/basic/tests.py b/tests/basic/tests.py index 909f3049b9..328ddc31f1 100644 --- a/tests/basic/tests.py +++ b/tests/basic/tests.py @@ -2,7 +2,7 @@ import threading from datetime import datetime, timedelta from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist -from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections +from django.db import DEFAULT_DB_ALIAS, DatabaseError, connections, models from django.db.models.manager import BaseManager from django.db.models.query import EmptyQuerySet, QuerySet from django.test import ( @@ -357,6 +357,23 @@ class ModelTest(TestCase): # hash) hash(Article()) + def test_missing_hash_not_inherited(self): + class NoHash(models.Model): + def __eq__(self, other): + return super.__eq__(other) + + with self.assertRaisesMessage(TypeError, "unhashable type: 'NoHash'"): + hash(NoHash(id=1)) + + def test_specified_parent_hash_inherited(self): + class ParentHash(models.Model): + def __eq__(self, other): + return super.__eq__(other) + + __hash__ = models.Model.__hash__ + + self.assertEqual(hash(ParentHash(id=1)), 1) + def test_delete_and_access_field(self): # Accessing a field after it's deleted from a model reloads its value. pub_date = datetime.now() |
