Skip to content

Commit c040105

Browse files
committed
add catalog list() test
Signed-off-by: Chris Snow <[email protected]>
1 parent 25ca49f commit c040105

File tree

2 files changed

+75
-11
lines changed

2 files changed

+75
-11
lines changed

hpecp/catalog.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
from tabulate import tabulate
2525

26-
from hpecp.exceptions import APIItemNotFoundException
27-
2826

2927
class CatalogController:
3028
"""This is the main class that users will interact with to talk to catalogs.
@@ -86,12 +84,6 @@ def get(self, catalog_id):
8684
response = self.client._request(
8785
url=catalog_id, http_method="get", description="catalog/get"
8886
)
89-
if response.json()["purpose"] != "proxy":
90-
raise APIItemNotFoundException(
91-
message="catalog not found with id: " + catalog_id,
92-
request_method="get",
93-
request_url=catalog_id,
94-
)
9587

9688
return Catalog(response.json())
9789

@@ -205,10 +197,9 @@ class CatalogList:
205197
"""
206198

207199
def __init__(self, json):
208-
self.json = [g for g in json if g["purpose"] == "proxy"]
200+
self.json = json
209201
self.catalogs = sorted(
210-
[Catalog(g) for g in json if g["purpose"] == "proxy"],
211-
key=attrgetter("id"),
202+
[Catalog(g) for g in json], key=attrgetter("id"),
212203
)
213204
self.display_columns = Catalog.default_display_fields
214205

tests/library/catalog_test.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from mock import patch
2525

2626
from hpecp import ContainerPlatformClient
27+
from hpecp.catalog import CatalogList
2728
from hpecp.exceptions import APIItemNotFoundException
2829

2930

@@ -139,3 +140,75 @@ def test_get_catalog(self, mock_get, mock_post):
139140
"'catalog not found with id: /api/v1/catalog/100'",
140141
):
141142
get_client().catalog.get("/api/v1/catalog/100")
143+
144+
145+
class TestCatalogList(unittest.TestCase):
146+
def mocked_requests_get(*args, **kwargs):
147+
if args[0] == "https://127.0.0.1:8080/api/v1/catalog/":
148+
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(),
206+
)
207+
raise RuntimeError("Unhandle GET request: " + args[0])
208+
209+
@patch("requests.get", side_effect=mocked_requests_get)
210+
@patch("requests.post", side_effect=mocked_requests_post)
211+
def test_list(self, mock_get, mock_post):
212+
213+
catalogList = get_client().catalog.list()
214+
self.assertIsInstance(catalogList, CatalogList)

0 commit comments

Comments
 (0)