mirror of
https://github.com/django/django.git
synced 2025-08-15 00:00:47 +00:00
Refs #373 -- Added Model._is_pk_set() abstraction to check if a Model's PK is set.
This commit is contained in:
parent
cdbd31960e
commit
5865ff5adc
13 changed files with 67 additions and 27 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue