Esempio n. 1
0
def test_pypi_index(content_type):
    headers = {}

    if content_type != "__empty__":
        headers["Content-Type"] = content_type

    app = pretend.stub()
    request = pretend.stub(
        args={},
        headers=headers,
        url_adapter=pretend.stub(
            build=pretend.call_recorder(
                lambda *a, **kw: "/",
            ),
        ),
    )
    # request for /pypi with no additional request information redirects
    # to site root
    #
    resp = pypi.pypi(app, request)
    assert resp.status_code == 301
    assert resp.headers["Location"] == "/"
    assert request.url_adapter.build.calls == [
        pretend.call(
            "warehouse.views.index",
            {},
            force_external=False,
        ),
    ]
Esempio n. 2
0
def test_pypi_index(content_type):
    headers = {}

    if content_type != "__empty__":
        headers["Content-Type"] = content_type

    app = pretend.stub()
    request = pretend.stub(
        args={},
        headers=headers,
        url_adapter=pretend.stub(
            build=pretend.call_recorder(
                lambda *a, **kw: "/",
            ),
        ),
    )
    # request for /pypi with no additional request information redirects
    # to site root
    #
    resp = pypi.pypi(app, request)
    assert resp.status_code == 301
    assert resp.headers["Location"] == "/"
    assert request.url_adapter.build.calls == [
        pretend.call(
            "warehouse.views.index",
            {},
            force_external=False,
        ),
    ]
Esempio n. 3
0
def test_pypi_route_xmlrpc(monkeypatch):
    app = pretend.stub()
    request = pretend.stub(
        headers={'Content-Type': 'text/xml'},
    )

    xmlrpc_stub = pretend.stub(
        handle_request=pretend.call_recorder(lambda *a: 'success')
    )
    monkeypatch.setattr(pypi, 'xmlrpc', xmlrpc_stub)

    # request for /pypi with no additional request information redirects
    # to site root
    #
    resp = pypi.pypi(app, request)

    assert xmlrpc_stub.handle_request.calls == [pretend.call(app, request)]
    assert resp == 'success'
Esempio n. 4
0
def test_pypi_route_action(monkeypatch):
    app = pretend.stub()
    request = pretend.stub(
        args={':action': 'test'},
        headers={},
    )

    _action_methods = {}
    monkeypatch.setattr(pypi, '_action_methods', _action_methods)

    @pypi.register('test')
    def test(app, request):
        test.called = True
        return 'success'

    resp = pypi.pypi(app, request)

    assert resp == 'success'
    assert test.called
Esempio n. 5
0
def test_pypi_route_action(monkeypatch):
    app = pretend.stub()
    request = pretend.stub(
        args={':action': 'test'},
        headers={},
    )

    _action_methods = {}
    monkeypatch.setattr(pypi, '_action_methods', _action_methods)

    @pypi.register('test')
    def test(app, request):
        test.called = True
        return 'success'

    resp = pypi.pypi(app, request)

    assert resp == 'success'
    assert test.called
Esempio n. 6
0
def test_pypi_index():
    app = pretend.stub()
    request = pretend.stub(
        headers={'Content-Type': None},     # GET request has no content-type
        url_adapter=pretend.stub(
            build=pretend.call_recorder(
                lambda *a, **kw: "/",
            ),
        ),
    )
    # request for /pypi with no additional request information redirects
    # to site root
    #
    resp = pypi.pypi(app, request)
    assert resp.status_code == 301
    assert resp.headers["Location"] == "/"
    assert request.url_adapter.build.calls == [
        pretend.call(
            "warehouse.views.index",
            {},
            force_external=False,
        ),
    ]