def test_no_root_dir_with_python_file(tmp_path, shared_datadir): """No root dir with Python file.""" hello_py = tmp_path / "hello.py" shutil.copy(shared_datadir / "hello.py", hello_py) project = ProjectMock(tmp_path, pyproject_toml=False, setup_py=False) project.files_to_lint.append(hello_py) error = f"NIP101 {ProjectViolations.NO_ROOT_DIR.message}" project.flake8().assert_single_error(error).cli_run( error, exit_code=2).cli_ls(error, exit_code=2)
def test_fetch_private_github_urls(request): """Fetch private GitHub URLs with a token on the query string.""" base_url = "https://raw.githubusercontent.com/user/private_repo/branch/path/to/nitpick-style" query_string = "?token=xxx" full_private_url = "{}{}{}".format(base_url, TOML_EXTENSION, query_string) body = """ ["pyproject.toml".tool.black] missing = "thing" """ responses.add(responses.GET, full_private_url, dedent(body), status=200) project = ProjectMock(request).pyproject_toml(""" [tool.nitpick] style = "{}{}" """.format(base_url, query_string)) project.flake8(offline=False).assert_single_error(""" NIP318 File pyproject.toml has missing values:\x1b[32m [tool.black] missing = "thing"\x1b[0m """) project.flake8(offline=True).assert_no_errors()
def test_fetch_private_github_urls(tmp_path): """Fetch private GitHub URLs with a token on the query string.""" gh_url = "https://github.com/user/private_repo/blob/branch/path/to/nitpick-style" file_token = "query-string-token-generated-by-github-for-private-files" full_raw_url = f"https://raw.githubusercontent.com/user/private_repo/branch/path/to/nitpick-style{TOML_EXTENSION}" body = """ ["pyproject.toml".tool.black] missing = "thing" """ responses.add(responses.GET, full_raw_url, dedent(body), status=200) project = ProjectMock(tmp_path).pyproject_toml(f""" [tool.nitpick] style = "{gh_url}?token={file_token}" """) project.flake8(offline=False).assert_single_error(f""" NIP318 File pyproject.toml has missing values:{SUGGESTION_BEGIN} [tool.black] missing = "thing"{SUGGESTION_END} """) token_on_basic_auth = b64encode(f"{file_token}:".encode()).decode().strip() assert responses.calls[0].request.headers[ "Authorization"] == f"Basic {token_on_basic_auth}" project.flake8(offline=True).assert_no_errors()