/usr/lib/python2.7/dist-packages/wsme/tests/test_protocols.py is in python-wsme 0.8.0-2ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | # encoding=utf8
import unittest
from wsme import WSRoot
from wsme.protocol import getprotocol, CallContext, Protocol
import wsme.protocol
class DummyProtocol(Protocol):
name = 'dummy'
content_types = ['', None]
def __init__(self):
self.hits = 0
def accept(self, req):
return True
def iter_calls(self, req):
yield CallContext(req)
def extract_path(self, context):
return ['touch']
def read_arguments(self, context):
self.lastreq = context.request
self.hits += 1
return {}
def encode_result(self, context, result):
return str(result)
def encode_error(self, context, infos):
return str(infos)
def test_getprotocol():
try:
getprotocol('invalid')
assert False, "ValueError was not raised"
except ValueError:
pass
class TestProtocols(unittest.TestCase):
def test_register_protocol(self):
wsme.protocol.register_protocol(DummyProtocol)
assert wsme.protocol.registered_protocols['dummy'] == DummyProtocol
r = WSRoot()
assert len(r.protocols) == 0
r.addprotocol('dummy')
assert len(r.protocols) == 1
assert r.protocols[0].__class__ == DummyProtocol
r = WSRoot(['dummy'])
assert len(r.protocols) == 1
assert r.protocols[0].__class__ == DummyProtocol
def test_Protocol(self):
p = wsme.protocol.Protocol()
assert p.iter_calls(None) is None
assert p.extract_path(None) is None
assert p.read_arguments(None) is None
assert p.encode_result(None, None) is None
assert p.encode_sample_value(None, None) == ('none', 'N/A')
assert p.encode_sample_params(None) == ('none', 'N/A')
assert p.encode_sample_result(None, None) == ('none', 'N/A')
|