def test_submit_form():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/xyz'
            assert kwargs.get('method') == 'POST'
            assert kwargs.get('follow_redirects') == False
            assert kwargs.get('data') == {'key': 'value', 'x': 'y'}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <input type="text" name="key" value="value" />
                <input type="text" name="x" value="" />
            </form>
        </html>
    """

    subject.submit_form({}, {'x': 'y'})

    assert subject.html == 'Success'
예제 #2
0
def test_get_404():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/abcdefg'
            assert kwargs.get('method') == 'GET'
            assert not kwargs.get('follow_redirects')

            return _Response(404, '')

    subject = Browser(Client())

    subject.get('/abcdefg', status=404)
예제 #3
0
def test_post():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/abcdefg'
            assert kwargs.get('method') == 'POST'
            assert not kwargs.get('follow_redirects')
            assert kwargs.get('data') == {'key': 'value'}

            return _Response(200, '')

    subject = Browser(Client())

    subject.post('/abcdefg', data={'key': 'value'})
예제 #4
0
def test_json_response():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/jsonendpoint'
            assert kwargs.get('method') == 'POST'

            return _JsonResponse(200, {'value': 7})

    subject = Browser(Client())

    subject.post('/jsonendpoint')

    assert subject.json == {'value': 7}
def test_get_404():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/abcdefg'
            assert kwargs.get('method') == 'GET'
            assert not kwargs.get('follow_redirects')

            return _Response(404, '')

    subject = Browser(Client())

    subject.get('/abcdefg', status=404)
def test_json_response():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/jsonendpoint'
            assert kwargs.get('method') == 'POST'

            return _JsonResponse(200, {'value': 7})

    subject = Browser(Client())

    subject.post('/jsonendpoint')

    assert subject.json == {'value': 7}
def test_post():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/abcdefg'
            assert kwargs.get('method') == 'POST'
            assert not kwargs.get('follow_redirects')
            assert kwargs.get('data') == {'key': 'value'}

            return _Response(200, '')

    subject = Browser(Client())

    subject.post('/abcdefg', data={'key': 'value'})
def test_submit_form_with_query_string():

    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/xyz'
            assert kwargs.get('query_string') == [('foo', 'bar')]
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz?foo=bar'
    subject.html = """
        <html>
            <form method="post">
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
def test_submit_form_with_action():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/some-action'
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post" action="/some-action">
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
def test_submit_form_by_get():

    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/abc'
            assert kwargs.get('query_string') == [('foo', 'bar'), ('f', 'v')]
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/abc?foo=bar'
    subject.html = """
        <html>
            <form method="get">
                <input type="text" name="f" value="v" />
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
def test_submit_form_checkbox_checked_turn_off():

    class Client():

        def open(self, url, *args, **kwargs):
            assert kwargs.get('data') == {}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <input type="checkbox" name="tgt" value="y" checked />
            </form>
        </html>
    """

    subject.submit_form({}, {'tgt': None})
    assert subject.html == 'Success'
def test_follow_link():

    class Client():

        def open(self, url, *args, **kwargs):
            assert url == '/right'
            assert kwargs.get('method') == 'GET'
            assert not kwargs.get('follow_redirects')

            return _Response(200, 'Sent OK')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html><body>
            <a href="/right" >The One</a>
            <a href="/wrong" >Not The One</a>
        </body></html>
    """

    subject.follow_link(text='The One')

    assert subject.html == 'Sent OK'
def test_submit_form_select_selected():

    class Client():
        def open(self, url, *args, **kwargs):
            assert kwargs.get('data') == {'tgt': '2'}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <select name="tgt">
                    <option value="1">One</option>
                    <option value="2" selected>Two</option>
                </select>
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
예제 #14
0
def test_submit_form_with_action():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/some-action'
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post" action="/some-action">
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
예제 #15
0
def test_submit_form_with_query_string():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/xyz'
            assert kwargs.get('query_string') == [('foo', 'bar')]
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz?foo=bar'
    subject.html = """
        <html>
            <form method="post">
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
예제 #16
0
def test_submit_form_by_get():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/abc'
            assert kwargs.get('query_string') == [('foo', 'bar'), ('f', 'v')]
            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/abc?foo=bar'
    subject.html = """
        <html>
            <form method="get">
                <input type="text" name="f" value="v" />
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
예제 #17
0
def test_submit_form_checkbox_checked_turn_off():
    class Client():
        def open(self, url, *args, **kwargs):
            assert kwargs.get('data') == {}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <input type="checkbox" name="tgt" value="y" checked />
            </form>
        </html>
    """

    subject.submit_form({}, {'tgt': None})
    assert subject.html == 'Success'
예제 #18
0
def test_follow_link():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/right'
            assert kwargs.get('method') == 'GET'
            assert not kwargs.get('follow_redirects')

            return _Response(200, 'Sent OK')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html><body>
            <a href="/right" >The One</a>
            <a href="/wrong" >Not The One</a>
        </body></html>
    """

    subject.follow_link(text='The One')

    assert subject.html == 'Sent OK'
예제 #19
0
def test_submit_form_select_selected():
    class Client():
        def open(self, url, *args, **kwargs):
            assert kwargs.get('data') == {'tgt': '2'}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <select name="tgt">
                    <option value="1">One</option>
                    <option value="2" selected>Two</option>
                </select>
            </form>
        </html>
    """

    subject.submit_form({}, {})
    assert subject.html == 'Success'
예제 #20
0
def test_submit_form():
    class Client():
        def open(self, url, *args, **kwargs):
            assert url == '/xyz'
            assert kwargs.get('method') == 'POST'
            assert kwargs.get('follow_redirects') == False
            assert kwargs.get('data') == {'key': 'value', 'x': 'y'}

            return _Response(200, 'Success')

    subject = Browser(Client())
    subject.url = '/xyz'
    subject.html = """
        <html>
            <form method="post">
                <input type="text" name="key" value="value" />
                <input type="text" name="x" value="" />
            </form>
        </html>
    """

    subject.submit_form({}, {'x': 'y'})

    assert subject.html == 'Success'