mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Refs #373 -- Added Model._is_pk_set() abstraction to check if a Model's PK is set.
This commit is contained in:
@@ -661,6 +661,31 @@ class ModelTest(TestCase):
|
||||
headline__startswith="Area",
|
||||
)
|
||||
|
||||
def test_is_pk_unset(self):
|
||||
cases = [
|
||||
Article(),
|
||||
Article(id=None),
|
||||
]
|
||||
for case in cases:
|
||||
with self.subTest(case=case):
|
||||
self.assertIs(case._is_pk_set(), False)
|
||||
|
||||
def test_is_pk_set(self):
|
||||
def new_instance():
|
||||
a = Article(pub_date=datetime.today())
|
||||
a.save()
|
||||
return a
|
||||
|
||||
cases = [
|
||||
Article(id=1),
|
||||
Article(id=0),
|
||||
Article.objects.create(pub_date=datetime.today()),
|
||||
new_instance(),
|
||||
]
|
||||
for case in cases:
|
||||
with self.subTest(case=case):
|
||||
self.assertIs(case._is_pk_set(), True)
|
||||
|
||||
|
||||
class ModelLookupTest(TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user