from decimal import Decimal
from cccheckout.models import Checkout
from django.core.handlers.base import BaseHandler
from django.test.client import RequestFactory


def testcase_adapter(request):
    """Doesn't do anything other than return the ckecout from the session"""
    return request.session['cccheckout']


class MockRequest(RequestFactory):
    def request(self, **request):
        "Construct a generic request object."
        request = RequestFactory.request(self, **request)
        handler = BaseHandler()
        handler.load_middleware()
        for middleware_method in handler._request_middleware:
            if middleware_method(request):
                raise Exception("Couldn't create request mock object - "
                                "request middleware returned a response")
        return request


class MockBasketLine(object):
    """use in tests only"""
    
    def __init__(self, price, quantity, description):
        self.price = Decimal('%s' % price)
        self.quantity = quantity
        self.description = description
