|
|
@@ -1,5 +1,6 @@
|
|
1
|
1
|
from django.test import TestCase
|
|
2
|
2
|
|
|
|
3
|
+from oscar.apps.catalogue.models import Product
|
|
3
|
4
|
from oscar.apps.partner import strategy
|
|
4
|
5
|
from oscar.test import factories
|
|
5
|
6
|
|
|
|
@@ -17,3 +18,12 @@ class TestUseFirstStockRecordMixin(TestCase):
|
|
17
|
18
|
|
|
18
|
19
|
def test_returns_none_when_no_stock_records(self):
|
|
19
|
20
|
self.assertIsNone(self.mixin.select_stockrecord(self.product))
|
|
|
21
|
+
|
|
|
22
|
+ def test_does_not_generate_additional_query_when_passed_product_from_base_queryset(self):
|
|
|
23
|
+ product = Product.objects.base_queryset().first()
|
|
|
24
|
+ # Regression test for https://github.com/django-oscar/django-oscar/issues/3875
|
|
|
25
|
+ # If passed a product from a queryset annotated by base_queryset, then
|
|
|
26
|
+ # the selector should not trigger any additional database queries because
|
|
|
27
|
+ # it should rely on the prefetched stock records.
|
|
|
28
|
+ with self.assertNumQueries(0):
|
|
|
29
|
+ self.mixin.select_stockrecord(product)
|