Ejemplo n.º 1
0
 def test_raise_importerror_if_app_raises_importerror(self):
     """
     This tests that Oscar doesn't fall back to using the Oscar catalogue
     app if the overriding app throws an ImportError.
     """
     apps = list(settings.INSTALLED_APPS)
     apps[apps.index('oscarapi')] = 'test_apps.oscarapi'
     with override_settings(INSTALLED_APPS=apps):
         with self.assertRaises(ImportError):
             get_api_class('oscarapi.middleware', 'HeaderSessionMiddleware')
Ejemplo n.º 2
0
import django
from django.conf.urls import url
from rest_framework.urlpatterns import format_suffix_patterns

from oscarapi.loading import get_api_classes, get_api_class

LoginView = get_api_class('oscarapi.views.login', 'LoginView')
api_root = get_api_class('oscarapi.views', 'api_root')

# basket views
(BasketView,
 AddProductView,
 AddVoucherView,
 shipping_methods,
 LineList,
 LineDetail,
 BasketLineDetail
 ) \
    = get_api_classes('oscarapi.views.basket',
                      (
                          'BasketView',
                          'AddProductView',
                          'AddVoucherView',
                          'shipping_methods',
                          'LineList',
                          'LineDetail',
                          'BasketLineDetail'
                      ))
# basic views
(LineAttributeList,
 LineAttributeDetail,
Ejemplo n.º 3
0
                          'LineAttributeSerializer',
                          'VoucherAddSerializer',
                          'VoucherSerializer'
                      ))

# product serializers
(ProductSerializer,
 AddProductSerializer
 ) \
    = get_api_classes('oscarapi.serializers.product',
                      (
                          'ProductSerializer',
                          'AddProductSerializer'
                      ))

ShippingMethodSerializer = get_api_class('oscarapi.serializers.checkout', 'ShippingMethodSerializer')


class BasketView(APIView):
    """
    Api for retrieving a user's basket.

    GET:
    Retrieve your basket.
    """
    serializer_class = BasketSerializer

    def get(self, request, format=None):
        basket = operations.get_basket(request)
        ser = self.serializer_class(basket, context={'request': request})
        return Response(ser.data)
Ejemplo n.º 4
0
(ProductLinkSerializer,
 ProductSerializer,
 AvailabilitySerializer,
 OptionSerializer,
 PartnerSerializer
 ) \
    = get_api_classes('oscarapi.serializers.product',
                      (
                          'ProductLinkSerializer',
                          'ProductSerializer',
                          'AvailabilitySerializer',
                          'OptionSerializer',
                          'PartnerSerializer'
                      ))

UserSerializer = get_api_class('oscarapi.serializers.login', 'UserSerializer')


# TODO: For all API's in this file, the permissions should be checked if they
# are sensible.
class CountryList(generics.ListAPIView):
    serializer_class = CountrySerializer
    queryset = Country.objects.all()


class CountryDetail(generics.RetrieveAPIView):
    serializer_class = CountrySerializer
    queryset = Country.objects.all()


class BasketList(generics.ListCreateAPIView):
Ejemplo n.º 5
0
 def test_raise_exception_when_bad_classname_used(self):
     with self.assertRaises(ClassNotFoundError):
         get_api_class('oscarapi.models', 'Monkey')
Ejemplo n.º 6
0
 def test_load_oscar_class_correctly(self):
     HeaderSessionMiddleware = get_api_class('oscarapi.middleware', 'HeaderSessionMiddleware')
     self.assertEqual('oscarapi.middleware', HeaderSessionMiddleware.__module__)
Ejemplo n.º 7
0
                          'LineAttributeSerializer',
                          'VoucherAddSerializer',
                          'VoucherSerializer'
                      ))

# product serializers
(ProductSerializer,
 AddProductSerializer
 ) \
    = get_api_classes('oscarapi.serializers.product',
                      (
                          'ProductSerializer',
                          'AddProductSerializer'
                      ))

ShippingMethodSerializer = get_api_class('oscarapi.serializers.checkout',
                                         'ShippingMethodSerializer')


class BasketView(APIView):
    """
    Api for retrieving a user's basket.

    GET:
    Retrieve your basket.
    """
    serializer_class = BasketSerializer

    def get(self, request, format=None):
        basket = operations.get_basket(request)
        ser = self.serializer_class(basket, context={'request': request})
        return Response(ser.data)