File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -379,9 +379,13 @@ def get_product_info(args=None):
379379""" ,
380380 formatter_class = RawTextHelpFormatter ,
381381 )
382- parser .add_argument ("product_code" , help = "The code of the product to get" )
383- args = parser .parse_args (args = args )
384382 client = get_client ()
383+ parser .add_argument (
384+ "product_code" ,
385+ help = "The code of the product to get" ,
386+ choices = [p ["code" ] for p in client .get_active_products ().json ()],
387+ )
388+ args = parser .parse_args (args = args )
385389 print_response (client .get_product_info_with_price (args .product_code ))
386390
387391
@@ -575,8 +579,12 @@ def check_xgrade(args=None):
575579""" ,
576580 formatter_class = RawTextHelpFormatter ,
577581 )
578- parser .add_argument ("product_code" , help = "The code of the product to check" )
579- args = parser .parse_args (args = args )
580582 client = get_client ()
583+ parser .add_argument (
584+ "product_code" ,
585+ help = "The code of the product to check" ,
586+ choices = [p ["code" ] for p in client .get_active_products ().json ()],
587+ )
588+ args = parser .parse_args (args = args )
581589 app_name = get_app_name ()
582590 print_response (client .check_xgrade (app_name , args .product_code ))
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ def setUp(self):
1313 "hypernode_api_python.commands.get_app_name"
1414 )
1515 self .get_app_name .return_value = "myappname"
16+ self .client .get_active_products .return_value .json .return_value = [
17+ {
18+ "code" : "FALCON_S_202203" ,
19+ },
20+ {
21+ "code" : "JACKAL_M_202201" ,
22+ },
23+ ]
1624
1725 def test_check_xgrade_gets_client (self ):
1826 check_xgrade (["FALCON_S_202203" ])
@@ -35,3 +43,7 @@ def test_check_xgrade_prints_product(self):
3543 self .print_response .assert_called_once_with (
3644 self .client .check_xgrade .return_value
3745 )
46+
47+ def test_check_xgrade_raises_if_product_not_found (self ):
48+ with self .assertRaises (SystemExit ):
49+ check_xgrade (["ProductThatDoesNotExist" ])
Original file line number Diff line number Diff line change @@ -9,6 +9,14 @@ def setUp(self):
99 )
1010 self .get_client = self .set_up_patch ("hypernode_api_python.commands.get_client" )
1111 self .client = self .get_client .return_value
12+ self .client .get_active_products .return_value .json .return_value = [
13+ {
14+ "code" : "FALCON_S_202203" ,
15+ },
16+ {
17+ "code" : "JACKAL_M_202201" ,
18+ },
19+ ]
1220
1321 def test_get_product_info_gets_client (self ):
1422 get_product_info (["FALCON_S_202203" ])
@@ -28,3 +36,7 @@ def test_get_product_info_prints_product(self):
2836 self .print_response .assert_called_once_with (
2937 self .client .get_product_info_with_price .return_value
3038 )
39+
40+ def test_get_product_raises_if_product_not_found (self ):
41+ with self .assertRaises (SystemExit ):
42+ get_product_info (["ProductThatDoesNotExist" ])
You can’t perform that action at this time.
0 commit comments