def test_github_url_query_token_retains_other_queryparams(monkeypatch): """Querystring isn't modified by the token switcharoo.""" parsed = GitHubURL.from_furl( furl( "https://github.com/foo/bar/blob/branch/filename.toml?leavemealone=ok" )) assert ("leavemealone", "ok") in parsed.url.query.params.items() parsed = GitHubURL.from_furl( furl( "https://github.com/foo/bar/blob/branch/filename.toml?token=somevar&leavemealone=ok" )) assert parsed.credentials == ("somevar", "") assert ("leavemealone", "ok") in parsed.url.query.params.items()
def test_github_url_with_missing_envvar_has_empty_credential(monkeypatch): """Environment var that doesn't exist is replaced with empty string.""" monkeypatch.delenv("MISSINGVAR", raising=False) parsed = GitHubURL.from_furl( furl( "https://github.com/foo/bar/blob/branch/filename.toml?token=$MISSINGVAR" )) assert parsed.credentials == ()
def get_default_style_url(github=False) -> furl: """Return the URL of the default style/preset.""" if github: return GitHubURL(PROJECT_OWNER, PROJECT_NAME, f"v{__version__}", (NITPICK_STYLE_TOML, )).long_protocol_url return furl(scheme=Scheme.PY, host=PROJECT_NAME, path=["resources", "presets", PROJECT_NAME])
def test_parsing_github_urls(original_url, expected_url, git_reference, raw_git_reference, at_reference): """Test a GitHub URL and its parts, raw URL, API URL.""" responses.add(responses.GET, "https://api.github.com/repos/andreoliwa/nitpick", '{"default_branch": "develop"}') gh = GitHubURL.from_furl(furl(original_url)) assert gh.owner == "andreoliwa" assert gh.repository == "nitpick" assert gh.git_reference == git_reference assert gh.path == ("src", "nitpick", "__init__.py") assert gh.raw_content_url == furl( f"https://raw.githubusercontent.com/andreoliwa/nitpick/{raw_git_reference}/src/nitpick/__init__.py" ) assert gh.url == furl(expected_url) assert gh.api_url == furl( "https://api.github.com/repos/andreoliwa/nitpick") assert gh.short_protocol_url == furl( f"gh://andreoliwa/nitpick{at_reference}/src/nitpick/__init__.py") assert gh.long_protocol_url == furl( f"github://andreoliwa/nitpick{at_reference}/src/nitpick/__init__.py")
def test_github_url_with_variable_query_token_has_correct_credential( url, monkeypatch): """Check private GitHub URLs with a token in various places are parsed correctly.""" monkeypatch.setenv("ENVVAR", "envvar-token") parsed = GitHubURL.from_furl(furl(url)) assert parsed.credentials == ("envvar-token", "")
def test_github_url_with_fixed_userinfo_token_has_correct_credential(url): """Check private GitHub URLs with a token in various places are parsed correctly.""" parsed = GitHubURL.from_furl(furl(url)) assert parsed.credentials == ("token", "")
def test_github_url_without_token_has_no_credentials(style_url): """Check private GitHub URLs with a token in various places are parsed correctly.""" parsed = GitHubURL.from_furl(furl(style_url)) assert parsed.credentials == ()