@@ -10,13 +10,18 @@ class TestClustersList(object):
1010 URL = "https://api.paperspace.io/clusters/getClusters"
1111
1212 COMMAND = ["clusters" , "list" ]
13+ COMMAND_WITH_LIMIT = COMMAND [:] + ["-l" , "2" ]
1314 COMMAND_WITH_OPTIONS_FILE = ["clusters" , "list" , "--optionsFile" , ] # path added in test
1415
1516 LIST_CLUSTERS = example_responses .EXAMPLE_CLUSTERS_LIST_RESPONSE
17+ LIMITED_LIST_CLUSTERS = example_responses .LIMITED_EXAMPLE_CLUSTERS_LIST_RESPONSE
1618
1719 DEFAULT_PARAMS = {
1820 "filter" : '{"limit": 20, "offset": 0, "where": {"isPrivate": true}}'
1921 }
22+ LIMITED_PARAMS = {
23+ "filter" : '{"limit": 2, "offset": 0, "where": {"isPrivate": true}}'
24+ }
2025
2126 COMMAND_WITH_API_KEY = ["clusters" , "list" , "--apiKey" , "some_key" ]
2227 EXPECTED_HEADERS = http_client .default_headers .copy ()
@@ -30,6 +35,16 @@ class TestClustersList(object):
3035| cluster_id_2 | cluster name 2 | Kubernetes Processing Site |
3136| cluster_id_3 | cluster name 3 | Job Cluster |
3237+--------------+----------------+----------------------------+
38+ """
39+ PAGINATED_LIST_STDOUT = """+--------------+----------------+----------------------------+
40+ | ID | Name | Type |
41+ +--------------+----------------+----------------------------+
42+ | cluster_id_1 | cluster name 1 | Job Cluster |
43+ | cluster_id_2 | cluster name 2 | Kubernetes Processing Site |
44+ +--------------+----------------+----------------------------+
45+
46+ Do you want to continue? [y/N]:
47+ Aborted!
3348"""
3449
3550 @mock .patch ("gradient.api_sdk.clients.http_client.requests.get" )
@@ -44,3 +59,32 @@ def test_should_send_get_request_and_print_list_of_clusters(self, get_patched):
4459 headers = self .EXPECTED_HEADERS ,
4560 json = None ,
4661 params = self .DEFAULT_PARAMS )
62+
63+ @mock .patch ("gradient.api_sdk.clients.http_client.requests.get" )
64+ def test_should_send_get_request_and_paginate_list_of_clusters (self , get_patched ):
65+ get_patched .return_value = MockResponse (self .LIMITED_LIST_CLUSTERS , 200 , "fake content" )
66+
67+ runner = CliRunner ()
68+ result = runner .invoke (cli .cli , self .COMMAND_WITH_LIMIT )
69+
70+ assert self .PAGINATED_LIST_STDOUT in str (result .output )
71+ get_patched .assert_called_once_with (self .URL ,
72+ headers = self .EXPECTED_HEADERS ,
73+ json = None ,
74+ params = self .LIMITED_PARAMS )
75+
76+ @mock .patch ("gradient.api_sdk.clients.http_client.requests.get" )
77+ def test_should_read_options_defined_in_a_config_file (self , get_patched , clusters_list_config_path ):
78+ get_patched .return_value = MockResponse (json_data = self .LIMITED_LIST_CLUSTERS ,
79+ status_code = 200 )
80+ command = self .COMMAND_WITH_OPTIONS_FILE [:] + [clusters_list_config_path ]
81+
82+ runner = CliRunner ()
83+ result = runner .invoke (cli .cli , command )
84+
85+ assert self .PAGINATED_LIST_STDOUT in str (result .output )
86+ get_patched .assert_called_once_with (self .URL ,
87+ headers = self .EXPECTED_HEADERS_WITH_CHANGED_API_KEY ,
88+ json = None ,
89+ params = self .LIMITED_PARAMS ,
90+ )
0 commit comments