Пример #1
0
def test_exporter_exports_requirements_txt_with_legacy_packages(
        tmp_dir, poetry):
    poetry.pool.add_repository(
        LegacyRepository(
            "custom",
            "https://example.com/simple",
            auth=Auth("https://example.com/simple", "foo", "bar"),
        ))
    poetry.locker.mock_lock_data({
        "package": [
            {
                "name": "foo",
                "version": "1.2.3",
                "category": "main",
                "optional": False,
                "python-versions": "*",
            },
            {
                "name": "bar",
                "version": "4.5.6",
                "category": "dev",
                "optional": False,
                "python-versions": "*",
                "source": {
                    "type": "legacy",
                    "url": "https://example.com/simple",
                    "reference": "",
                },
            },
        ],
        "metadata": {
            "python-versions": "*",
            "content-hash": "123456789",
            "hashes": {
                "foo": ["12345"],
                "bar": ["67890"]
            },
        },
    })
    exporter = Exporter(poetry)

    exporter.export("requirements.txt",
                    Path(tmp_dir),
                    "requirements.txt",
                    dev=True)

    with (Path(tmp_dir) / "requirements.txt").open(encoding="utf-8") as f:
        content = f.read()

    expected = """\
--extra-index-url https://example.com/simple

bar==4.5.6 \\
    --hash=sha256:67890
foo==1.2.3 \\
    --hash=sha256:12345
"""

    assert expected == content
Пример #2
0
def test_auth_with_request_on_different_hosts():
    auth = Auth("https://python-poetry.org", "foo", "bar")

    request = Request("GET", "https://pendulum.eustace.io/docs/")
    assert "Authorization" not in request.headers

    request = auth(request)

    assert "Authorization" not in request.headers
Пример #3
0
def test_auth_with_request_on_the_same_host():
    auth = Auth("https://python-poetry.org", "foo", "bar")

    request = Request("GET", "https://python-poetry.org/docs/")
    assert "Authorization" not in request.headers

    request = auth(request)

    assert "Authorization" in request.headers
    assert request.headers["Authorization"] == "Basic {}".format(
        decode(base64.b64encode(encode(":".join(("foo", "bar"))))))
Пример #4
0
def test_auth_with_request_with_same_authentication():
    auth = Auth("https://poetry.eustace.io", "foo", "bar")

    request = Request("GET", "https://*****:*****@poetry.eustace.io/docs/")
    assert "Authorization" not in request.headers

    request = auth(request)

    assert "Authorization" in request.headers
    assert request.headers["Authorization"] == "Basic {}".format(
        decode(base64.b64encode(encode(":".join(("foo", "bar"))))))
Пример #5
0
def test_username_password_special_chars():
    auth = Auth("http://legacy.foo.bar", "user:"******"/%2Fp@ssword")
    repo = MockRepository(auth=auth)

    assert "http://user%3A:%2F%252Fp%[email protected]" == repo.authenticated_url