示例#1
0
def test_put_simple(fake_repository, monkeypatch):
    """Straightforward test."""
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    put_license_in_file("0BSD")

    assert (fake_repository / "LICENSES/0BSD.txt").read_text() == "hello\n"
示例#2
0
def test_put_empty_dir(empty_directory, monkeypatch):
    """Create a LICENSES/ directory if one does not yet exist."""
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    put_license_in_file("0BSD")

    assert (empty_directory / "LICENSES").exists()
    assert (empty_directory / "LICENSES/0BSD.txt").read_text() == "hello\n"
示例#3
0
def test_put_request_exception(fake_repository, monkeypatch):
    """There was an error while downloading the license file."""
    # pylint: disable=unused-argument
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse(status_code=404))

    with pytest.raises(requests.RequestException):
        put_license_in_file("0BSD")
示例#4
0
def test_put_git_repository(git_repository, monkeypatch):
    """Find the LICENSES/ directory in a Git repository."""
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    os.chdir("src")
    put_license_in_file("0BSD")

    assert (git_repository / "LICENSES/0BSD.txt").read_text() == "hello\n"
示例#5
0
def test_put_file_exists(fake_repository, monkeypatch):
    """The to-be-downloaded file already exists."""
    # pylint: disable=unused-argument
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))

    with pytest.raises(FileExistsError) as exc_info:
        put_license_in_file("GPL-3.0-or-later")
    assert Path(exc_info.value.filename).name == "GPL-3.0-or-later.txt"
示例#6
0
def test_put_in_licenses_dir(fake_repository, monkeypatch):
    """Put license file in current directory, if current directory is the
    LICENSES/ directory.
    """
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    os.chdir("LICENSES")
    put_license_in_file("0BSD")

    assert (fake_repository / "LICENSES/0BSD.txt").read_text() == "hello\n"
示例#7
0
def test_put_custom_exception(empty_directory, monkeypatch):
    """Download the exception into a custom file."""
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    put_license_in_file("Autoconf-exception-3.0", destination="foo")

    assert ((empty_directory / "foo").read_text() ==
            "Valid-Exception-Identifier: Autoconf-exception-3.0\n"
            "Exception-Text:\n"
            "\n"
            "hello\n")
示例#8
0
def test_put_custom_output(empty_directory, monkeypatch):
    """Download the license into a custom file."""
    monkeypatch.setattr(requests, "get",
                        lambda _: MockResponse("hello\n", 200))
    put_license_in_file("0BSD", destination="foo")

    assert ((empty_directory /
             "foo").read_text() == "Valid-License-Identifier: 0BSD\n"
            "License-Text:\n"
            "\n"
            "hello\n")