Esempio n. 1
0
def test_timeout(server, timeout, pause, is_timeout):

    class Handler(connect.ConnectHandler):

        def on_ready(self):
            connect.TIMERS.add(self._ready, pause).start()

        def _ready(self):
            super(Handler, self).on_ready()

    def on_complete(rc, result):
        if is_timeout:
            assert rc == 1
            assert result == 'timeout'
        else:
            assert rc == 0

    connect.run(
        connect.connect(
            on_complete,
            URL,
            timeout=timeout / 1000.0,
            handler=Handler,
        )
    )
Esempio n. 2
0
def test_failed_to_connect():
    def on_complete(rc, result):
        assert rc == 1
        assert result == 'failed to connect'

    connect.run(connect.connect(
        on_complete,
        URL,
        is_json=False,
    ))
Esempio n. 3
0
def test_method(server, method):
    def on_complete(rc, result):
        assert rc == 0
        assert result['method'] == method

    connect.run(connect.connect(
        on_complete,
        URL,
        method=method,
    ))
Esempio n. 4
0
def test_non_json(server):
    def on_complete(rc, result):
        assert rc == 0
        assert isinstance(result, str)
        assert json.loads(result)

    connect.run(connect.connect(
        on_complete,
        URL,
        is_json=False,
    ))
Esempio n. 5
0
def test_headers(server):
    def on_complete(rc, result):
        assert rc == 0
        assert result['headers']['whatever'] == 'yeah'

    connect.run(
        connect.connect(
            on_complete,
            URL,
            headers=dict(whatever='yeah'),
        ))
Esempio n. 6
0
def test_query(server):
    def on_complete(rc, result):
        assert rc == 0
        assert result['query_string'] == 'foo=bar&akk=eek'
        assert len(result['query']) == 2
        assert result['query']['foo'] == 'bar'
        assert result['query']['akk'] == 'eek'

    connect.run(connect.connect(
        on_complete,
        URL + '?foo=bar&akk=eek',
    ))
Esempio n. 7
0
def test_dict_body(server, method, body, has_query_string):
    def on_complete(rc, result):
        assert rc == 0
        assert (len(result['query_string']) > 0) is has_query_string
        assert (len(result['body']) > 0) is not has_query_string

    connect.run(connect.connect(
        on_complete,
        URL,
        body=body,
        method=method,
    ))
Esempio n. 8
0
def test_body(server):

    DATA = 'test'

    def on_complete(rc, result):
        assert rc == 0
        assert result['body'] == DATA

    connect.run(connect.connect(
        on_complete,
        URL,
        body=DATA,
    ))
Esempio n. 9
0
def test_method(server, method):

    def on_complete(rc, result):
        assert rc == 0
        assert result['method'] == method

    connect.run(
        connect.connect(
            on_complete,
            URL,
            method=method,
        )
    )
Esempio n. 10
0
def test_failed_to_connect():

    def on_complete(rc, result):
        assert rc == 1
        assert result == 'failed to connect'

    connect.run(
        connect.connect(
            on_complete,
            URL,
            is_json=False,
        )
    )
Esempio n. 11
0
def test_headers(server):

    def on_complete(rc, result):
        assert rc == 0
        assert result['headers']['whatever'] == 'yeah'

    connect.run(
        connect.connect(
            on_complete,
            URL,
            headers=dict(whatever='yeah'),
        )
    )
Esempio n. 12
0
def test_non_json(server):

    def on_complete(rc, result):
        assert rc == 0
        assert isinstance(result, str)
        assert json.loads(result)

    connect.run(
        connect.connect(
            on_complete,
            URL,
            is_json=False,
        )
    )
Esempio n. 13
0
def test_wrapper(server):
    class Wrapper(object):
        def __init__(self, result):
            pass

    def on_complete(rc, result):
        assert rc == 0
        assert isinstance(result, Wrapper)

    connect.run(connect.connect(
        on_complete,
        URL,
        wrapper=Wrapper,
    ))
Esempio n. 14
0
def test_query(server):

    def on_complete(rc, result):
        assert rc == 0
        assert result['query_string'] == 'foo=bar&akk=eek'
        assert len(result['query']) == 2
        assert result['query']['foo'] == 'bar'
        assert result['query']['akk'] == 'eek'

    connect.run(
        connect.connect(
            on_complete,
            URL + '?foo=bar&akk=eek',
        )
    )
Esempio n. 15
0
def test_body(server):

    DATA = 'test'

    def on_complete(rc, result):
        assert rc == 0
        assert result['body'] == DATA

    connect.run(
        connect.connect(
            on_complete,
            URL,
            body=DATA,
        )
    )
Esempio n. 16
0
def test_dict_body(server, method, body, has_query_string):

    def on_complete(rc, result):
        assert rc == 0
        assert (len(result['query_string']) > 0) is has_query_string
        assert (len(result['body']) > 0) is not has_query_string

    connect.run(
        connect.connect(
            on_complete,
            URL,
            body=body,
            method=method,
        )
    )
Esempio n. 17
0
def test_form(server):
    def on_complete(rc, result):
        assert rc == 0
        assert result['headers']['content-type'] == \
            'application/x-www-form-urlencoded'
        assert result['body'] in ('whatever=yeah&yeah=whatever',
                                  'yeah=whatever&whatever=yeah')

    connect.run(
        connect.connect(
            on_complete,
            URL,
            body=dict(whatever='yeah', yeah='whatever'),
            is_form=True,
        ))
Esempio n. 18
0
def test_wrapper(server):

    class Wrapper(object):
        def __init__(self, result):
            pass

    def on_complete(rc, result):
        assert rc == 0
        assert isinstance(result, Wrapper)

    connect.run(
        connect.connect(
            on_complete,
            URL,
            wrapper=Wrapper,
        )
    )
Esempio n. 19
0
def test_form(server):

    def on_complete(rc, result):
        assert rc == 0
        assert result['headers']['content-type'] == \
            'application/x-www-form-urlencoded'
        assert result['body'] in (
                'whatever=yeah&yeah=whatever',
                'yeah=whatever&whatever=yeah'
            )

    connect.run(
        connect.connect(
            on_complete,
            URL,
            body=dict(whatever='yeah', yeah='whatever'),
            is_form=True,
        )
    )
Esempio n. 20
0
def test_timeout(server, timeout, pause, is_timeout):
    class Handler(connect.ConnectHandler):
        def on_ready(self):
            connect.TIMERS.add(self._ready, pause).start()

        def _ready(self):
            super(Handler, self).on_ready()

    def on_complete(rc, result):
        if is_timeout:
            assert rc == 1
            assert result == 'timeout'
        else:
            assert rc == 0

    connect.run(
        connect.connect(
            on_complete,
            URL,
            timeout=timeout / 1000.0,
            handler=Handler,
        ))