#!/usr/bin/env python
#coding: utf-8

from unittest import TestCase

from redis import Redis, ResponseError

from .common import *

class LuaReturnErrorTestCase(TestCase):

    def test_lua_return_error(self):
        """Test the error described on issue 404 is fixed.

        https://github.com/twitter/twemproxy/issues/404

        """
        r = getconn()
        p = r.pipeline(transaction=False)

        p.set("test_key", "bananas!")
        p.eval('return {err="dummyerror"}', 1, "dummy_key")
        p.get("test_key")

        set_result, eval_result, get_result = p.execute(raise_on_error=False)

        assert_equal(True, set_result)

        assert_equal(True, isinstance(eval_result, ResponseError))
        assert_equal(str(eval_result), "dummyerror")

        assert_equal(get_result, b"bananas!")

Add testcase of error with no space
Add testcase of error with no space

Cherry-picked from https://github.com/twitter/twemproxy/pull/406

The alternate fix 6c962267d7fab8595940367b0cc8fb6f75f66cea was used

Amended to work with the updated test framework

Related to https://github.com/twitter/twemproxy/issues/404

Co-Authored-By: Tyson Andre <a29c2fb3fa57e6364b2f4bc0c65d65b890f64bb3@hotmail.com>
