Skip to content

Commit

Permalink
Merge pull request #106 from taaviteska/fix/price-availability-views
Browse files Browse the repository at this point in the history
Fetch products properly in ProductPrice and ProductAvailability views
  • Loading branch information
Martijn Jacobs committed Sep 11, 2017
2 parents 9aed1e1 + 3aefe13 commit 41d8a3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions oscarapi/tests/testproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ def test_product_price(self):
self.response.assertStatusEqual(200)
self.assertIn('excl_tax', self.response.body)

self.response = self.get(reverse('product-price', args=(999999,)))
self.response.assertStatusEqual(404)

def test_product_availability(self):
"See if we get the availability information"
self.response = self.get(reverse('product-availability', args=(1,)))
self.response.assertStatusEqual(200)
self.assertIn('num_available', self.response.body)

self.response = self.get(reverse('product-availability', args=(999999,)))
self.response.assertStatusEqual(404)
6 changes: 4 additions & 2 deletions oscarapi/views/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ class ProductDetail(generics.RetrieveAPIView):


class ProductPrice(generics.RetrieveAPIView):
queryset = Product.objects.all()

def get(self, request, pk=None, format=None):
product = Product.objects.get(id=pk)
product = self.get_object()
strategy = Selector().strategy(request=request, user=request.user)
ser = serializers.PriceSerializer(
strategy.fetch_for_product(product).price,
Expand All @@ -103,9 +104,10 @@ def get(self, request, pk=None, format=None):


class ProductAvailability(generics.RetrieveAPIView):
queryset = Product.objects.all()

def get(self, request, pk=None, format=None):
product = Product.objects.get(id=pk)
product = self.get_object()
strategy = Selector().strategy(request=request, user=request.user)
ser = serializers.AvailabilitySerializer(
strategy.fetch_for_product(product).availability,
Expand Down

0 comments on commit 41d8a3d

Please sign in to comment.