mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Added tests for using attnames to assign OneToOne and Foreign Key fields.
This commit is contained in:
committed by
Mariusz Felisiak
parent
4b4e68a7a6
commit
619c9a4f49
@@ -152,6 +152,22 @@ class ManyToOneTests(TestCase):
|
||||
self.assertFalse(hasattr(self.r2.article_set, 'remove'))
|
||||
self.assertFalse(hasattr(self.r2.article_set, 'clear'))
|
||||
|
||||
def test_assign_fk_id_value(self):
|
||||
parent = Parent.objects.create(name='jeff')
|
||||
child1 = Child.objects.create(name='frank', parent=parent)
|
||||
child2 = Child.objects.create(name='randy', parent=parent)
|
||||
parent.bestchild = child1
|
||||
parent.save()
|
||||
parent.bestchild_id = child2.pk
|
||||
parent.save()
|
||||
self.assertEqual(parent.bestchild_id, child2.pk)
|
||||
self.assertFalse(Parent.bestchild.is_cached(parent))
|
||||
self.assertEqual(parent.bestchild, child2)
|
||||
self.assertTrue(Parent.bestchild.is_cached(parent))
|
||||
# Reassigning the same value doesn't clear cached instance.
|
||||
parent.bestchild_id = child2.pk
|
||||
self.assertTrue(Parent.bestchild.is_cached(parent))
|
||||
|
||||
def test_selects(self):
|
||||
self.r.article_set.create(headline="John's second story", pub_date=datetime.date(2005, 7, 29))
|
||||
self.r2.article_set.create(headline="Paul's story", pub_date=datetime.date(2006, 1, 17))
|
||||
|
||||
Reference in New Issue
Block a user