18
18
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
19
19
# OTHER DEALINGS IN THE SOFTWARE.
20
20
21
+
22
+ import os
23
+ import sys
21
24
import unittest
25
+ from textwrap import dedent
22
26
23
27
import requests
24
28
from mock import patch
25
29
26
30
from hpecp import ContainerPlatformClient
27
31
from hpecp .catalog import CatalogList
28
32
from hpecp .exceptions import APIItemNotFoundException
33
+ import tempfile
29
34
30
35
31
36
class MockResponse :
@@ -142,67 +147,68 @@ def test_get_catalog(self, mock_get, mock_post):
142
147
get_client ().catalog .get ("/api/v1/catalog/100" )
143
148
144
149
150
+ catalog_list_json = {
151
+ "_links" : {
152
+ "self" : {"href" : "/api/v1/catalog/" },
153
+ "feedlog" : {"href" : "/api/v1/catalog/feedlog" },
154
+ "feed" : [
155
+ {
156
+ "href" : "http://127.0.0.1:8080/api/v1/feed/local" ,
157
+ "name" : "Feed generated from local bundles." ,
158
+ },
159
+ {
160
+ "href" : "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json" ,
161
+ "name" : "BlueData EPIC-5.0 catalog feed for docker" ,
162
+ },
163
+ ],
164
+ },
165
+ "catalog_api_version" : 6 ,
166
+ "feeds_refresh_period_seconds" : 86400 ,
167
+ "feeds_read_counter" : 5 ,
168
+ "catalog_write_counter" : 5 ,
169
+ "_embedded" : {
170
+ "independent_catalog_entries" : [
171
+ {
172
+ "_links" : {
173
+ "self" : {"href" : "/api/v1/catalog/29" },
174
+ "feed" : [
175
+ {
176
+ "href" : "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json" ,
177
+ "name" : "BlueData EPIC-5.0 catalog feed for docker" ,
178
+ }
179
+ ],
180
+ },
181
+ "distro_id" : "bluedata/spark240juphub7xssl" ,
182
+ "label" : {
183
+ "name" : "Spark240" ,
184
+ "description" : "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node" ,
185
+ },
186
+ "version" : "2.8" ,
187
+ "timestamp" : 0 ,
188
+ "isdebug" : False ,
189
+ "osclass" : ["centos" ],
190
+ "logo" : {
191
+ "checksum" : "1471eb59356066ed4a06130566764ea6" ,
192
+ "url" : "http://10.1.0.53/catalog/logos/bluedata-spark240juphub7xssl-2.8" ,
193
+ },
194
+ "documentation" : {
195
+ "checksum" : "52f53f1b2845463b9e370d17fb80bea6" ,
196
+ "mimetype" : "text/markdown" ,
197
+ "file" : "/opt/bluedata/catalog/documentation/bluedata-spark240juphub7xssl-2.8" ,
198
+ },
199
+ "state" : "initialized" ,
200
+ "state_info" : "" ,
201
+ }
202
+ ]
203
+ },
204
+ }
205
+
206
+
145
207
class TestCatalogList (unittest .TestCase ):
146
208
def mocked_requests_get (* args , ** kwargs ):
147
209
if args [0 ] == "https://127.0.0.1:8080/api/v1/catalog/" :
148
210
return MockResponse (
149
- json_data = {
150
- "_links" : {
151
- "self" : {"href" : "/api/v1/catalog/" },
152
- "feedlog" : {"href" : "/api/v1/catalog/feedlog" },
153
- "feed" : [
154
- {
155
- "href" : "http://127.0.0.1:8080/api/v1/feed/local" ,
156
- "name" : "Feed generated from local bundles." ,
157
- },
158
- {
159
- "href" : "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json" ,
160
- "name" : "BlueData EPIC-5.0 catalog feed for docker" ,
161
- },
162
- ],
163
- },
164
- "catalog_api_version" : 6 ,
165
- "feeds_refresh_period_seconds" : 86400 ,
166
- "feeds_read_counter" : 5 ,
167
- "catalog_write_counter" : 5 ,
168
- "_embedded" : {
169
- "independent_catalog_entries" : [
170
- {
171
- "_links" : {
172
- "self" : {"href" : "/api/v1/catalog/29" },
173
- "feed" : [
174
- {
175
- "href" : "https://s3.amazonaws.com/bluedata-catalog/bundles/catalog/external/docker/EPIC-5.0/feeds/feed.json" ,
176
- "name" : "BlueData EPIC-5.0 catalog feed for docker" ,
177
- }
178
- ],
179
- },
180
- "distro_id" : "bluedata/spark240juphub7xssl" ,
181
- "label" : {
182
- "name" : "Spark240" ,
183
- "description" : "Spark240 multirole with Jupyter Notebook, Jupyterhub with SSL and gateway node" ,
184
- },
185
- "version" : "2.8" ,
186
- "timestamp" : 0 ,
187
- "isdebug" : False ,
188
- "osclass" : ["centos" ],
189
- "logo" : {
190
- "checksum" : "1471eb59356066ed4a06130566764ea6" ,
191
- "url" : "http://10.1.0.53/catalog/logos/bluedata-spark240juphub7xssl-2.8" ,
192
- },
193
- "documentation" : {
194
- "checksum" : "52f53f1b2845463b9e370d17fb80bea6" ,
195
- "mimetype" : "text/markdown" ,
196
- "file" : "/opt/bluedata/catalog/documentation/bluedata-spark240juphub7xssl-2.8" ,
197
- },
198
- "state" : "initialized" ,
199
- "state_info" : "" ,
200
- }
201
- ]
202
- },
203
- },
204
- status_code = 200 ,
205
- headers = dict (),
211
+ json_data = catalog_list_json , status_code = 200 , headers = dict (),
206
212
)
207
213
raise RuntimeError ("Unhandle GET request: " + args [0 ])
208
214
@@ -212,3 +218,45 @@ def test_list(self, mock_get, mock_post):
212
218
213
219
catalogList = get_client ().catalog .list ()
214
220
self .assertIsInstance (catalogList , CatalogList )
221
+
222
+
223
+ class TestCLI (unittest .TestCase ):
224
+ def mocked_requests_get (* args , ** kwargs ):
225
+ if args [0 ] == "https://127.0.0.1:8080/api/v1/catalog/" :
226
+ return MockResponse (
227
+ json_data = catalog_list_json , status_code = 200 , headers = dict (),
228
+ )
229
+ raise RuntimeError ("Unhandle GET request: " + args [0 ])
230
+
231
+ @patch ("requests.post" , side_effect = mocked_requests_post )
232
+ @patch ("requests.get" , side_effect = mocked_requests_get )
233
+ def test_cli (self , mock_post , mock_get ):
234
+
235
+ sys .path .insert (0 , os .path .abspath ("../../" ))
236
+ from bin import cli
237
+
238
+ file_data = dedent (
239
+ """[default]
240
+ api_host = 127.0.0.1
241
+ api_port = 8080
242
+ use_ssl = True
243
+ verify_ssl = False
244
+ warn_ssl = True
245
+ username = admin
246
+ password = admin123"""
247
+ )
248
+
249
+ tmp = tempfile .NamedTemporaryFile (delete = True )
250
+ try :
251
+ tmp .write (file_data .encode ("utf-8" ))
252
+ tmp .flush ()
253
+
254
+ cli .HPECP_CONFIG_FILE = tmp .name
255
+
256
+ hpecp = cli .CLI ()
257
+ hpecp .catalog .list ()
258
+
259
+ self .assertTrue (True )
260
+
261
+ finally :
262
+ tmp .close ()
0 commit comments