@@ -554,6 +554,93 @@ def test_move(self):
554
554
"qux did not move to dst" ,
555
555
)
556
556
557
+ def test_fetch_releases_no_assets (self ):
558
+ """Test _fetch_releases for unexpected values.
559
+
560
+ Expects a Github asset's name field to have the suffix '.tar.gz' and
561
+ the prefix 'UMU-Proton' or 'GE-Proton'. Or the name field to have 'sum'
562
+ suffix, for the digest file.
563
+
564
+ A tuple should always be returned. Otherwise, it indicates that Github
565
+ has changed its API or we had change file names. An exception should
566
+ never be raised.
567
+ """
568
+ result = None
569
+ mock_gh_release = {
570
+ "assets" : [
571
+ {
572
+ "name" : "foo" ,
573
+ "browser_download_url" : "" ,
574
+ },
575
+ {
576
+ "name" : "bar" ,
577
+ "browser_download_url" : "" ,
578
+ },
579
+ ]
580
+ }
581
+ # Mock the call to urlopen
582
+ mock_resp = MagicMock ()
583
+ mock_resp .read .return_value = b"foo"
584
+ mock_resp .status = 200
585
+ mock_resp .__enter__ .return_value = mock_resp
586
+ # Mock PROTONPATH="", representing a download to UMU-Proton
587
+ os .environ ["PROTONPATH" ] = ""
588
+ with (
589
+ patch .object (umu_proton , "urlopen" , return_value = mock_resp ),
590
+ patch .object (umu_proton , "loads" , return_value = mock_gh_release ),
591
+ ):
592
+ result = umu_proton ._fetch_releases ()
593
+ self .assertTrue (
594
+ result is not None , "Expected a value, received None"
595
+ )
596
+ self .assertTrue (
597
+ isinstance (result , tuple ), f"Expected tuple, received { result } "
598
+ )
599
+ result_len = len (result )
600
+ self .assertFalse (
601
+ result_len ,
602
+ f"Expected tuple with no len, received len { result_len } " ,
603
+ )
604
+
605
+ def test_fetch_releases (self ):
606
+ """Test _fetch_releases."""
607
+ result = None
608
+ mock_gh_release = {
609
+ "assets" : [
610
+ {
611
+ "name" : "sum" ,
612
+ "browser_download_url" : "" ,
613
+ },
614
+ {
615
+ "name" : "UMU-Proton.tar.gz" ,
616
+ "browser_download_url" : "" ,
617
+ },
618
+ ]
619
+ }
620
+ # Mock the call to urlopen
621
+ mock_resp = MagicMock ()
622
+ mock_resp .read .return_value = b"foo"
623
+ mock_resp .status = 200
624
+ mock_resp .__enter__ .return_value = mock_resp
625
+ # Mock PROTONPATH="", representing a download to UMU-Proton
626
+ os .environ ["PROTONPATH" ] = ""
627
+ with (
628
+ patch .object (umu_proton , "urlopen" , return_value = mock_resp ),
629
+ patch .object (umu_proton , "loads" , return_value = mock_gh_release ),
630
+ ):
631
+ result = umu_proton ._fetch_releases ()
632
+ self .assertTrue (
633
+ result is not None , "Expected a value, received None"
634
+ )
635
+ self .assertTrue (
636
+ isinstance (result , tuple ), f"Expected tuple, received { result } "
637
+ )
638
+ result_len = len (result )
639
+ self .assertTrue (
640
+ result_len ,
641
+ f"Expected tuple with len, received len { result_len } " ,
642
+ )
643
+
557
644
def test_update_proton (self ):
558
645
"""Test _update_proton."""
559
646
mock_protons = [Path (mkdtemp ()), Path (mkdtemp ())]
0 commit comments