def testHandlingSingleResult(): """ A single RPC result must not be returned in a list. """ worker = WorkerOpsiJsonRpc(service=None, request=FakeRequest(), resource=None) worker._rpcs = [FakeRPC("Hallo Welt")] result = worker._generateResponse(None) assert 200 == result.code assert result.headers.hasHeader('content-type') assert ['application/json;charset=utf-8'] == result.headers.getRawHeaders('content-type') assert not result.headers.hasHeader('content-encoding') assert '"Hallo Welt"' == str(result.stream.read())
def testHandlingSingleResultConsistingOfList(): """ If a single result is made the result is a list this list must not be unpacked. """ worker = WorkerOpsiJsonRpc(service=None, request=FakeRequest(), resource=None) worker._rpcs = [FakeRPC(["Eins", "Zwei", "Drei"])] result = worker._generateResponse(None) assert 200 == result.code assert result.headers.hasHeader('content-type') assert ['application/json;charset=utf-8'] == result.headers.getRawHeaders('content-type') assert not result.headers.hasHeader('content-encoding') assert '["Eins", "Zwei", "Drei"]' == str(result.stream.read())
def testHandlingMultipleRPCs(): """ With multiple RPCs the results are returned in a list. We do not use any compression in this testcase. """ worker = WorkerOpsiJsonRpc(service=None, request=FakeRequest(), resource=None) worker._rpcs = [ FakeRPC(), FakeRPC(1), FakeRPC(u"FÄKE!"), FakeRPC({"Narziss": "Morgen Nicht Geboren"}) ] result = worker._generateResponse(None) assert 200 == result.code assert result.headers.hasHeader('content-type') assert ['application/json;charset=utf-8'] == result.headers.getRawHeaders('content-type') assert not result.headers.hasHeader('content-encoding') assert '[null, 1, "F\xc3\x84KE!", {"Narziss": "Morgen Nicht Geboren"}]' == str(result.stream.read())