1111
1212
1313@pytest .mark .parametrize (
14- "repository_type, repo_url, revision, raises, expected_url" ,
14+ "repository_type, repo_url, token, revision, raises, expected_url" ,
1515 (
1616 (
1717 # HG, no revision
1818 "hg" ,
1919 "https://hg.mozilla.org/fake_repo" ,
2020 None ,
21+ None ,
2122 False ,
2223 "https://hg.mozilla.org/fake_repo/raw-file/default/fake_path" ,
2324 ),
2425 (
2526 # HG, revision
2627 "hg" ,
2728 "https://hg.mozilla.org/fake_repo" ,
29+ None ,
2830 "rev" ,
2931 False ,
3032 "https://hg.mozilla.org/fake_repo/raw-file/rev/fake_path" ,
3436 "git" ,
3537 "https://github.com/org/repo" ,
3638 None ,
39+ None ,
3740 False ,
3841 "https://api.github.com/repos/org/repo/contents/fake_path" ,
3942 ),
4245 "git" ,
4346 "https://github.com/org/repo/" ,
4447 None ,
48+ None ,
4549 False ,
4650 "https://api.github.com/repos/org/repo/contents/fake_path" ,
4751 ),
4852 (
4953 # Git, revision
5054 "git" ,
5155 "https://github.com/org/repo" ,
56+ None ,
57+ "rev" ,
58+ False ,
59+ "https://api.github.com/repos/org/repo/contents/fake_path?ref=rev" ,
60+ ),
61+ (
62+ # Git, revision, token
63+ "git" ,
64+ "https://github.com/org/repo" ,
65+ "mytoken" ,
5266 "rev" ,
5367 False ,
5468 "https://api.github.com/repos/org/repo/contents/fake_path?ref=rev" ,
5771 # Raise on private git url
5872 "git" ,
5973 "git@github.com:org/repo" ,
74+ None ,
6075 "rev" ,
6176 Exception ,
6277 None ,
6580 # Raise on unrecognized git url
6681 "git" ,
6782 "https://unknown-git-server.com:org/repo" ,
83+ None ,
6884 "rev" ,
6985 Exception ,
7086 None ,
7490 "unknown" ,
7591 None ,
7692 None ,
93+ None ,
7794 Exception ,
7895 None ,
7996 ),
8097 ),
8198)
82- def test_get_file (mocker , repository_type , repo_url , revision , raises , expected_url ):
99+ def test_get_file (mocker , repository_type , repo_url , token , revision , raises , expected_url ):
83100 """Add coverage to ``Repository.get_file``."""
84101
85102 fake_session = mocker .MagicMock ()
@@ -90,6 +107,7 @@ def test_get_file(mocker, repository_type, repo_url, revision, raises, expected_
90107 repo = repository .Repository (
91108 repo_url = repo_url ,
92109 repository_type = repository_type ,
110+ github_token = token ,
93111 )
94112 if raises :
95113 with pytest .raises (raises ):
@@ -99,6 +117,8 @@ def test_get_file(mocker, repository_type, repo_url, revision, raises, expected_
99117 expected_headers = {}
100118 if repo_url .startswith ("https://github.com" ):
101119 expected_headers = {"Accept" : "application/vnd.github.raw+json" }
120+ if token :
121+ expected_headers ["Authorization" ] = f"token { token } "
102122 fake_session .get .assert_called_with (expected_url , headers = expected_headers , timeout = 60 )
103123
104124
0 commit comments