def test_ajax(): product = get_default_product() commands = get_basket_command_dispatcher(get_request_with_basket()) commands.ajax = True rv = commands.handle("add", kwargs=dict(product_id=product.pk, quantity=-3)) assert isinstance(rv, JsonResponse) assert commands.basket.product_count == 0
def test_custom_basket_command(): ok = [] def noop(**kwargs): ok.append(kwargs) def get_custom_command(command, **kwargs): if command == "test_custom_basket_command": return noop old_n_receivers = len(get_basket_command_handler.receivers) try: get_basket_command_handler.connect(get_custom_command, dispatch_uid="test_custom_basket_command") commands = get_basket_command_dispatcher(request=get_request_with_basket()) commands.handle("test_custom_basket_command") assert ok # heh. finally: get_basket_command_handler.disconnect(dispatch_uid="test_custom_basket_command") assert old_n_receivers == len(get_basket_command_handler.receivers)
def test_custom_basket_command(): ok = [] def noop(**kwargs): ok.append(kwargs) def get_custom_command(command, **kwargs): if command == "test_custom_basket_command": return noop old_n_receivers = len(get_basket_command_handler.receivers) try: get_basket_command_handler.connect( get_custom_command, dispatch_uid="test_custom_basket_command") commands = get_basket_command_dispatcher( request=get_request_with_basket()) commands.handle("test_custom_basket_command") assert ok # heh. finally: get_basket_command_handler.disconnect( dispatch_uid="test_custom_basket_command") assert old_n_receivers == len(get_basket_command_handler.receivers)
def dispatch(self, request, *args, **kwargs): command = request.REQUEST.get("command") if command: return get_basket_command_dispatcher(request).handle(command) else: return get_basket_view()(request, *args, **kwargs)
def test_nonajax(): product = get_default_product() commands = get_basket_command_dispatcher(get_request_with_basket()) commands.ajax = False with pytest.raises(Exception): commands.handle("add", kwargs=dict(product_id=product.pk, quantity=-3))
def test_dne(): commands = get_basket_command_dispatcher(get_request_with_basket()) with pytest.raises(Exception): commands.handle("_doesnotexist_")