Exemple #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,
        )
    )
Exemple #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,
    ))
Exemple #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,
    ))
Exemple #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,
    ))
Exemple #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'),
        ))
Exemple #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',
    ))
Exemple #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,
    ))
Exemple #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,
    ))
Exemple #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,
        )
    )
Exemple #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,
        )
    )
Exemple #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'),
        )
    )
Exemple #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,
        )
    )
Exemple #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,
    ))
Exemple #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',
        )
    )
Exemple #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,
        )
    )
Exemple #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,
        )
    )
Exemple #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,
        ))
Exemple #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,
        )
    )
Exemple #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,
        )
    )
Exemple #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,
        ))