@@ -155,6 +155,47 @@ def test_unknown_badge_incorrect_repo(self):
155155 <text x="52" y="14">unknown</text>
156156 </g>
157157</svg>
158+ """
159+ badge = response .content .decode ("utf-8" )
160+ badge = [line .strip () for line in badge .split ("\n " )]
161+ expected_badge = [line .strip () for line in expected_badge .split ("\n " )]
162+ assert expected_badge == badge
163+ assert response .status_code == status .HTTP_200_OK
164+
165+ def test_unknown_badge_private_repo_wrong_token (self ):
166+ gh_owner = OwnerFactory (service = "github" )
167+ RepositoryFactory (
168+ author = gh_owner , active = True , private = True , name = "repo1" , image_token = "asdf"
169+ )
170+ response = self ._get (
171+ kwargs = {
172+ "service" : "gh" ,
173+ "owner_username" : gh_owner .username ,
174+ "repo_name" : "repo1" ,
175+ "ext" : "svg" ,
176+ "bundle" : "asdf" ,
177+ }
178+ )
179+ expected_badge = """<svg xmlns="http://www.w3.org/2000/svg" width="106" height="20">
180+ <linearGradient id="CodecovBadgeGradient" x2="0" y2="100%">
181+ <stop offset="0" stop-color="#bbb" stop-opacity=".1" />
182+ <stop offset="1" stop-opacity=".1" />
183+ </linearGradient>
184+ <mask id="CodecovBadgeMask106px">
185+ <rect width="106" height="20" rx="3" fill="#fff" />
186+ </mask>
187+ <g mask="url(#CodecovBadgeMask106px)">
188+ <path fill="#555" d="M0 0h47v20H0z" />
189+ <path fill="#2C2433" d="M47 0h59v20H47z" />
190+ <path fill="url(#CodecovBadgeGradient)" d="M0 0h106v20H0z" />
191+ </g>
192+ <g fill="#fff" text-anchor="left" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
193+ <text x="5" y="15" fill="#010101" fill-opacity=".3">bundle</text>
194+ <text x="5" y="14">bundle</text>
195+ <text x="52" y="15" fill="#010101" fill-opacity=".3">unknown</text>
196+ <text x="52" y="14">unknown</text>
197+ </g>
198+ </svg>
158199"""
159200 badge = response .content .decode ("utf-8" )
160201 badge = [line .strip () for line in badge .split ("\n " )]
@@ -464,4 +505,36 @@ def test_bundle_badge_unsupported_precision_defaults_to_2(self, mock_load_report
464505 badge = [line .strip () for line in badge .split ("\n " )]
465506 expected_badge = [line .strip () for line in expected_badge .split ("\n " )]
466507 assert expected_badge == badge
508+
509+ @patch ("graphs.views.load_report" )
510+ def test_bundle_badge_private_repo_correct_token (self , mock_load_report ):
511+ gh_owner = OwnerFactory (service = "github" )
512+ repo = RepositoryFactory (
513+ author = gh_owner , active = True , private = True , name = "repo1" , image_token = "asdf"
514+ )
515+ branch = BranchFactory (name = "main" , repository = repo )
516+ repo .branch = branch
517+ commit = CommitFactory (
518+ repository = repo , commitid = repo .branch .head , branch = "main"
519+ )
520+ branch .head = commit .commitid
521+
522+ mock_load_report .return_value = MockBundleAnalysisReport ()
523+
524+ response = self ._get (
525+ kwargs = {
526+ "service" : "gh" ,
527+ "owner_username" : gh_owner .username ,
528+ "repo_name" : "repo1" ,
529+ "ext" : "txt" ,
530+ "bundle" : "asdf" ,
531+ },
532+ data = {"token" : "asdf" },
533+ )
534+ expected_badge = "1.23MB"
535+
536+ badge = response .content .decode ("utf-8" )
537+ badge = [line .strip () for line in badge .split ("\n " )]
538+ expected_badge = [line .strip () for line in expected_badge .split ("\n " )]
539+ assert expected_badge == badge
467540 assert response .status_code == status .HTTP_200_OK
0 commit comments