151
151
),
152
152
)
153
153
154
+ BaseTestCase .registerHttpGetHandler (
155
+ url = "https://127.0.0.1:8080/api/v1/catalog/102" ,
156
+ response = MockResponse (
157
+ json_data = {"garbage" }, status_code = 200 , headers = dict (),
158
+ ),
159
+ )
160
+
154
161
BaseTestCase .registerHttpGetHandler (
155
162
url = "https://127.0.0.1:8080/api/v1/catalog" ,
156
163
response = MockResponse (
@@ -591,66 +598,8 @@ def test_list_with_query_and_text_output(self, mock_post, mock_get):
591
598
592
599
593
600
class TestCLIGet (BaseTestCase ):
594
- def mocked_requests_get (* args , ** kwargs ):
595
- if args [0 ] == "https://127.0.0.1:8080/api/v1/catalog/100" :
596
- return MockResponse (
597
- json_data = {
598
- "_links" : {
599
- "self" : {"href" : "/api/v1/catalog/100" },
600
- "feed" : [
601
- {
602
- "href" : (
603
- "https://s3.amazonaws.com/bluedata-catalog/"
604
- "bundles/catalog/external/docker/EPIC-5.0/"
605
- "feeds/feed.json"
606
- ),
607
- "name" : (
608
- "BlueData EPIC-5.0 catalog feed for docker"
609
- ),
610
- }
611
- ],
612
- },
613
- "id" : "/api/v1/catalog/100" ,
614
- "distro_id" : "bluedata/spark240juphub7xssl" ,
615
- "label" : {
616
- "name" : "Spark240" ,
617
- "description" : ("The description" ),
618
- },
619
- "version" : "2.8" ,
620
- "timestamp" : 0 ,
621
- "isdebug" : False ,
622
- "osclass" : ["centos" ],
623
- "logo" : {
624
- "checksum" : "1471eb59356066ed4a06130566764ea6" ,
625
- "url" : (
626
- "http://10.1.0.53/catalog/logos/"
627
- "bluedata-spark240juphub7xssl-2.8"
628
- ),
629
- },
630
- "documentation" : {
631
- "checksum" : "52f53f1b2845463b9e370d17fb80bea6" ,
632
- "mimetype" : "text/markdown" ,
633
- "file" : (
634
- "/opt/bluedata/catalog/documentation/"
635
- "bluedata-spark240juphub7xssl-2.8"
636
- ),
637
- },
638
- "state" : "initialized" ,
639
- "state_info" : "" ,
640
- },
641
- status_code = 200 ,
642
- headers = dict (),
643
- )
644
- if args [0 ] == "https://127.0.0.1:8080/api/v1/catalog/101" :
645
- raise APIItemNotFoundException (
646
- message = "catalog not found with id: " + "/api/v1/catalog/101" ,
647
- request_method = "get" ,
648
- request_url = args [0 ],
649
- )
650
- raise RuntimeError ("Unhandle GET request: " + args [0 ])
651
-
652
601
@patch ("requests.post" , side_effect = BaseTestCase .httpPostHandlers )
653
- @patch ("requests.get" , side_effect = mocked_requests_get )
602
+ @patch ("requests.get" , side_effect = BaseTestCase . httpGetHandlers )
654
603
def test_get_output_is_valid_yaml (self , mock_post , mock_get ):
655
604
656
605
self .maxDiff = None
@@ -665,7 +614,7 @@ def test_get_output_is_valid_yaml(self, mock_post, mock_get):
665
614
self .fail ("Output should be valid yaml" )
666
615
667
616
@patch ("requests.post" , side_effect = BaseTestCase .httpPostHandlers )
668
- @patch ("requests.get" , side_effect = mocked_requests_get )
617
+ @patch ("requests.get" , side_effect = BaseTestCase . httpGetHandlers )
669
618
def test_get_yaml_output_is_valid (self , mock_post , mock_get ):
670
619
671
620
self .maxDiff = None
@@ -695,7 +644,7 @@ def test_get_yaml_output_is_valid(self, mock_post, mock_get):
695
644
id: /api/v1/catalog/100
696
645
isdebug: false
697
646
label:
698
- description: The description
647
+ description: Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node
699
648
name: Spark240
700
649
logo:
701
650
checksum: 1471eb59356066ed4a06130566764ea6
@@ -715,7 +664,7 @@ def test_get_yaml_output_is_valid(self, mock_post, mock_get):
715
664
)
716
665
717
666
@patch ("requests.post" , side_effect = BaseTestCase .httpPostHandlers )
718
- @patch ("requests.get" , side_effect = mocked_requests_get )
667
+ @patch ("requests.get" , side_effect = BaseTestCase . httpGetHandlers )
719
668
def test_get_json_output (self , mock_post , mock_get ):
720
669
721
670
self .maxDiff = None
@@ -746,7 +695,10 @@ def test_get_json_output(self, mock_post, mock_get):
746
695
"distro_id" : "bluedata/spark240juphub7xssl" ,
747
696
"label" : {
748
697
"name" : "Spark240" ,
749
- "description" : "The description" ,
698
+ "description" : (
699
+ "Spark240 multirole with Jupyter Notebook, Jupyterhub"
700
+ " with SSL and gateway node"
701
+ ),
750
702
},
751
703
"state" : "initialized" ,
752
704
"version" : "2.8" ,
@@ -763,7 +715,7 @@ def test_get_json_output(self, mock_post, mock_get):
763
715
)
764
716
765
717
@patch ("requests.post" , side_effect = BaseTestCase .httpPostHandlers )
766
- @patch ("requests.get" , side_effect = mocked_requests_get )
718
+ @patch ("requests.get" , side_effect = BaseTestCase . httpGetHandlers )
767
719
def test_get_output_with_invalid_catalog_id (self , mock_post , mock_get ):
768
720
769
721
with self .assertRaises (SystemExit ) as cm :
@@ -794,12 +746,12 @@ def mocked_requests_garbage_data(*args, **kwargs):
794
746
raise RuntimeError ("Unhandle GET request: " + args [0 ])
795
747
796
748
@patch ("requests.post" , side_effect = BaseTestCase .httpPostHandlers )
797
- @patch ("requests.get" , side_effect = mocked_requests_garbage_data )
749
+ @patch ("requests.get" , side_effect = BaseTestCase . httpGetHandlers )
798
750
def test_get_output_with_unknown_exception (self , mock_post , mock_get ):
799
751
800
752
with self .assertRaises (SystemExit ) as cm :
801
753
hpecp = self .cli .CLI ()
802
- hpecp .catalog .get ("/api/v1/catalog/101 " )
754
+ hpecp .catalog .get ("/api/v1/catalog/102 " )
803
755
804
756
self .assertEqual (cm .exception .code , 1 )
805
757
0 commit comments