def test_proxy(): return #ssh -v -N -D 127.0.0.1:1080 test.domain.com api.init() listener = scheme.PassiveListener('api') scheme.register(listener) type, host, port = 'socks5', '127.0.0.1', 1080 def check_output(text): wc = plugintools.wildcard('<html><head><title>Current IP Check</title></head><body>Current IP Address: *</body></html>') return wc.match(text) resp = requests.get('http://checkip.dyndns.org/') proxyless_text = resp.text.strip() assert check_output(proxyless_text) interface.call('proxy', 'set', type=type, host=host, port=port) data = listener.pop().values()[0] debugtools.compare_dict(data, {'proxy.port': 1080, 'proxy.enabled': True, 'proxy.type': 'socks5', 'proxy.host': '127.0.0.1', 'action': 'update', 'table': 'config'}) resp = requests.get('http://checkip.dyndns.org/') proxy_text = resp.text.strip() assert check_output(proxy_text) assert proxy_text != proxyless_text interface.call('proxy', 'remove') data = listener.pop().values()[0] debugtools.compare_dict(data, {'proxy.port': None, 'proxy.enabled': None, 'proxy.type': None, 'proxy.host': None, 'action': 'update', 'table': 'config'}) resp = requests.get('http://checkip.dyndns.org/') proxyless_text2 = resp.text.strip() assert check_output(proxyless_text2) assert proxy_text != proxyless_text2 assert proxyless_text == proxyless_text2
loader.init() import sys import gevent from client import scheme, loader, event, interface, core import httpserver loader.init() sys.stdout = sys._old_stdout sys.stderr = sys._old_stderr listener = scheme.PassiveListener(['api', 'db']) scheme.register(listener) DEFAULT_MAX_CHUNKS = 2 interface.call('config', 'set', key='download.max_chunks', value=DEFAULT_MAX_CHUNKS) interface.call('config', 'set', key='download.overwrite', value='overwrite') ####################### import socket from client import logger logger.ignore_exceptions.append(socket.error) class Test(object): def setUp(self): httpserver.start()
def test_scheme(): listener = DebugListener('test') scheme.register(listener) with transaction: test = TableTest(test="hallo", evented="this is an event", getter={"foo": "bar"}, listed=['abcdef']) data = listener.pop() si = data.keys()[0] - 1 assert data == { si + 1: { 'evented': 'this is an event', 'dicted': None, 'test': 'hallo', 'getter': 'bar', 'listed': ['abcdef'], 'action': 'new', 'table': 'test', 'id': si + 1 } } with transaction: test2 = TableTest(test="hallo test 2", evented="this is an event", getter={"foo": "bar"}, listed=['abcdef']) assert listener.pop() == { si + 2: { 'evented': 'this is an event', 'dicted': None, 'test': 'hallo test 2', 'getter': 'bar', 'listed': ['abcdef'], 'action': 'new', 'table': 'test', 'id': si + 2 } } with transaction: with transaction: test3 = TableTest(test="hallo test 3") test3.listed = ['foo', 'bar'] assert listener.pop() == { si + 3: { 'evented': None, 'dicted': None, 'test': 'hallo test 3', 'getter': None, 'listed': ['foo', 'bar'], 'action': 'new', 'table': 'test', 'id': si + 3 } } with transaction: with transaction: test3.table_delete() data = listener.pop() assert data == { si + 3: { 'action': 'delete', 'table': 'test', 'id': si + 3 } } with transaction: with transaction: test3 = TableTest(test="hallo test 3") with transaction: test3.table_delete() assert listener.pop() == {} with transaction: test.dicted = {"hallo": "welt"} assert listener.pop() == { si + 1: { 'action': 'update', 'table': 'test', 'id': si + 1, 'dicted': { 'hallo': 'welt' } } } with transaction: test.listed.append('ghijkl') with transaction: test.dicted['ficken'] = 'klar' assert listener.pop() == { si + 1: { 'action': 'update', 'table': 'test', 'dicted': { 'hallo': 'welt', 'ficken': 'klar' }, 'id': si + 1, 'listed': ['abcdef', 'ghijkl'] } } with transaction: test.listed += ["mnopq"] test.dicted['ficken'] = 'logo' assert listener.pop() == { si + 1: { 'action': 'update', 'table': 'test', 'dicted': { 'hallo': 'welt', 'ficken': 'logo' }, 'id': si + 1, 'listed': ['abcdef', 'ghijkl', 'mnopq'] } } with transaction: test.listed.remove('ghijkl') del test.dicted['ficken'] test.dicted.update({"arsch": "loch"}) assert listener.pop() == { si + 1: { 'action': 'update', 'table': 'test', 'dicted': { 'hallo': 'welt', 'arsch': 'loch' }, 'id': si + 1, 'listed': ['abcdef', 'mnopq'] } } try: with transaction: test.listed.remove('abcdef') del test.dicted['arsch'] raise ValueError('foo') except ValueError: pass assert listener.pop() == {} with transaction: with transaction: test2.table_delete() assert listener.pop() == { si + 2: { 'action': 'delete', 'table': 'test', 'id': si + 2 } } try: with transaction: test.table_delete() raise ValueError('foo') except ValueError: pass assert listener.pop() == {} try: with transaction: test2.listed = None assert False except TransactionError: pass assert listener.pop() == {} try: with transaction: test2.listed.append('append on deleted table') assert False except TransactionError: pass assert listener.pop() == {} with transaction: test.table_delete() assert listener.pop() == { si + 1: { 'action': 'delete', 'table': 'test', 'id': si + 1 } }
loader.init() import sys import gevent from client import debugtools, scheme, loader, event, interface import httpserver loader.init() sys.stdout = sys._old_stdout sys.stderr = sys._old_stderr listener = scheme.PassiveListener(['api', 'db']) scheme.register(listener) DEFAULT_MAX_CHUNKS = 2 SLEEP = (2.5, 1.2) interface.call('config', 'set', key='download.max_chunks', value=DEFAULT_MAX_CHUNKS) interface.call('config', 'set', key='download.overwrite', value='overwrite') ####################### import socket from client import logger logger.ignore_exceptions.append(socket.error) class Test(object): testurl = httpserver.url+'/10mb.bin'
def test_scheme(): listener = DebugListener('test') scheme.register(listener) with transaction: test = TableTest(test="hallo", evented="this is an event", getter={"foo": "bar"}, listed=['abcdef']) data = listener.pop() si = data.keys()[0] - 1 assert data == {si+1: {'evented': 'this is an event', 'dicted': None, 'test': 'hallo', 'getter': 'bar', 'listed': ['abcdef'], 'action': 'new', 'table': 'test', 'id': si+1}} with transaction: test2 = TableTest(test="hallo test 2", evented="this is an event", getter={"foo": "bar"}, listed=['abcdef']) assert listener.pop() == {si+2: {'evented': 'this is an event', 'dicted': None, 'test': 'hallo test 2', 'getter': 'bar', 'listed': ['abcdef'], 'action': 'new', 'table': 'test', 'id': si+2}} with transaction: with transaction: test3 = TableTest(test="hallo test 3") test3.listed = ['foo', 'bar'] assert listener.pop() == {si+3: {'evented': None, 'dicted': None, 'test': 'hallo test 3', 'getter': None, 'listed': ['foo', 'bar'], 'action': 'new', 'table': 'test', 'id': si+3}} with transaction: with transaction: test3.table_delete() data = listener.pop() assert data == {si+3: {'action': 'delete', 'table': 'test', 'id': si+3}} with transaction: with transaction: test3 = TableTest(test="hallo test 3") with transaction: test3.table_delete() assert listener.pop() == {} with transaction: test.dicted = {"hallo": "welt"} assert listener.pop() == {si+1: {'action': 'update', 'table': 'test', 'id': si+1, 'dicted': {'hallo': 'welt'}}} with transaction: test.listed.append('ghijkl') with transaction: test.dicted['ficken'] = 'klar' assert listener.pop() == {si+1: {'action': 'update', 'table': 'test', 'dicted': {'hallo': 'welt', 'ficken': 'klar'}, 'id': si+1, 'listed': ['abcdef', 'ghijkl']}} with transaction: test.listed += ["mnopq"] test.dicted['ficken'] = 'logo' assert listener.pop() == {si+1: {'action': 'update', 'table': 'test', 'dicted': {'hallo': 'welt', 'ficken': 'logo'}, 'id': si+1, 'listed': ['abcdef', 'ghijkl', 'mnopq']}} with transaction: test.listed.remove('ghijkl') del test.dicted['ficken'] test.dicted.update({"arsch": "loch"}) assert listener.pop() == {si+1: {'action': 'update', 'table': 'test', 'dicted': {'hallo': 'welt', 'arsch': 'loch'}, 'id': si+1, 'listed': ['abcdef', 'mnopq']}} try: with transaction: test.listed.remove('abcdef') del test.dicted['arsch'] raise ValueError('foo') except ValueError: pass assert listener.pop() == {} with transaction: with transaction: test2.table_delete() assert listener.pop() == {si+2: {'action': 'delete', 'table': 'test', 'id': si+2}} try: with transaction: test.table_delete() raise ValueError('foo') except ValueError: pass assert listener.pop() == {} try: with transaction: test2.listed = None assert False except TransactionError: pass assert listener.pop() == {} try: with transaction: test2.listed.append('append on deleted table') assert False except TransactionError: pass assert listener.pop() == {} with transaction: test.table_delete() assert listener.pop() == {si+1: {'action': 'delete', 'table': 'test', 'id': si+1}}
def main(): scheme.register(scheme.DebugListener(('db', 'api', 'config'), 0)) app.main()