Exemplo n.º 1
0
def test_fetcher_current(inp, expected):
    session = pretend.stub(headers={}, get=lambda x: pretend.stub(text=inp))
    client = pretend.stub()

    fetcher = fetchers.PyPIFetcher(session=session, client=client)

    assert fetcher.current() == expected
Exemplo n.º 2
0
def test_fetcher_session_initialize(monkeypatch):
    monkeypatch.setattr(requests, "session", mock.Mock(spec_set=["verify"]))

    client = pretend.stub()
    fetcher = fetchers.PyPIFetcher(client=client)
    certificate = os.path.join(os.path.dirname(fetchers.__file__), "PyPI.crt")

    assert fetcher.session.verify == certificate
Exemplo n.º 3
0
def test_fetcher_files(url, https_url, content):
    session_get = mock.Mock(return_value=pretend.stub(content=content))
    session = pretend.stub(headers={}, get=session_get)
    client = pretend.stub()

    fetcher = fetchers.PyPIFetcher(session=session, client=client)

    assert fetcher.file(url) == content

    session_get.assert_called_once_with(https_url)
Exemplo n.º 4
0
def test_fetcher_classifiers(response_text, expected):
    session = pretend.stub(
        headers={},
        get=lambda x: pretend.stub(text=response_text),
    )
    client = pretend.stub()

    fetcher = fetchers.PyPIFetcher(session=session, client=client)

    assert fetcher.classifiers() == expected
Exemplo n.º 5
0
def test_fetcher_distributions(project, version, client_response, expected):
    session = pretend.stub(headers={})
    client = pretend.stub(release_urls=lambda _1, _2: client_response)
    validators = pretend.stub(release_urls=pretend.stub(validate=lambda x: x))

    fetcher = fetchers.PyPIFetcher(
        session=session,
        client=client,
        validators=validators,
    )

    assert list(fetcher.distributions(project, version)) == expected
Exemplo n.º 6
0
def test_fetcher_release(project, version, client_response, expected):
    session = pretend.stub(headers={})
    client = pretend.stub(release_data=lambda _1, _2: client_response)
    validators = pretend.stub(release_data=pretend.stub(validate=lambda x: x))

    fetcher = fetchers.PyPIFetcher(
        session=session,
        client=client,
        validators=validators,
    )

    assert fetcher.release(project, version) == expected
Exemplo n.º 7
0
def test_fetcher_projects(client_response, expected):
    session = pretend.stub(headers={})
    client = pretend.stub(list_packages=lambda: client_response)
    validators = pretend.stub(list_packages=pretend.stub(validate=lambda x: x))

    fetcher = fetchers.PyPIFetcher(
        session=session,
        client=client,
        validators=validators,
    )

    assert fetcher.projects() == expected
Exemplo n.º 8
0
def test_fetcher_versions(project, client_response, expected):
    session = pretend.stub(headers={})
    client = pretend.stub(package_releases=lambda _1, _2: client_response)
    validators = pretend.stub(
        package_releases=pretend.stub(validate=lambda x: x), )

    fetcher = fetchers.PyPIFetcher(
        session=session,
        client=client,
        validators=validators,
    )

    assert fetcher.versions(project) == expected
Exemplo n.º 9
0
def test_fetcher_client_initialize(monkeypatch):
    http_transport_stub = pretend.stub()
    https_transport_stub = pretend.stub()

    http_transport = mock.Mock(return_value=http_transport_stub)
    https_transport = mock.Mock(return_value=https_transport_stub)
    client = mock.Mock()

    monkeypatch.setattr(xmlrpc2.client, "HTTPTransport", http_transport)
    monkeypatch.setattr(xmlrpc2.client, "HTTPSTransport", https_transport)
    monkeypatch.setattr(xmlrpc2.client, "Client", client)

    session = pretend.stub(headers={})

    fetchers.PyPIFetcher(session=session)

    http_transport.assert_called_once_with(session=session)
    https_transport.assert_called_once_with(session=session)
    client.assert_called_once_with(
        "https://pypi.python.org/pypi",
        transports=[http_transport_stub, https_transport_stub],
    )