I have this code in a django test:
stockitem_retailer = StockItem.objects.filter(retailer=test_retailer).first()
test_subcategory = SubCategory.objects.create(category=test_category, name="outdoors")
stockitem_retailer.product.subcategory = test_subcategory
stockitem_retailer.save()
pdb.set_trace()
self.assertTrue(StockItem.objects.filter(product__subcategory=test_subcategory, retailer=test_retailer).exists())
The code above gets a StockItem
object with retailer=test_retailer
, then id adds a created subcategory "outdoors" to the stockitem.product.subcategory
relation. Why then the test does not pass?
This is what I get from pdb
:
(Pdb) test_subcategory
<SubCategory: outdoors>
(Pdb) test_retailer
<Retailer: mi-super>
(Pdb) stockitem_retailer.product.subcategory
<SubCategory: outdoors>
(Pdb) stockitem_retailer.retailer
<Retailer: mi-super>
(Pdb) self.assertTrue(StockItem.objects.filter(product__subcategory=test_subcategory, retailer=test_retailer).exists())
*** AssertionError: False is not true
I've being looking at this code for hours now, I can't se the bug. Please help.