Skip to content

Commit 8efc6de

Browse files
committed
fix: improvement PR comments
1 parent 99320ba commit 8efc6de

File tree

6 files changed

+90
-34
lines changed

6 files changed

+90
-34
lines changed

examples/feeds/create_feed.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
platform=PLATFORM,
2828
workspace=workspace_id,
2929
)
30-
created_feed_name = client.create_feed(feed=feed_request).name
30+
feed_details = client.create_feed(feed=feed_request)
3131

3232
print("Feed created Successfully.")
33-
print(f"Created feed name: {created_feed_name}")
33+
print(f"Created feed details: {feed_details}")
3434

3535
except ApiException as exp:
3636
print(exp)

examples/feeds/delete_feed.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,31 @@
22

33
from nisystemlink.clients.core import ApiException, HttpConfiguration
44
from nisystemlink.clients.feeds._feeds_client import FeedsClient
5+
from nisystemlink.clients.feeds.models import Platform
6+
from nisystemlink.clients.feeds.utilities import get_feed_by_name
57

68

7-
FEED_ID = ""
9+
FEED_NAME = "EXAMPLE FEED" # Name of the feed.
10+
PLATFORM = Platform.WINDOWS
811

912
server_url = "" # SystemLink API URL
1013
server_api_key = "" # SystemLink API key
14+
workspace_id = (
15+
None # None uses Default workspace. Replace with Systemlink workspace id.
16+
)
1117

1218
# Please provide the valid API key and API URL for client intialization.
1319
client = FeedsClient(HttpConfiguration(api_key=server_api_key, server_uri=server_url))
1420

1521
# Deleting Feed.
1622
try:
17-
created_feed_name = client.delete_feed(id=FEED_ID)
18-
print("Feed deleted successfully.")
23+
# To query available feeds.
24+
query_feeds_response = client.query_feeds(platform=PLATFORM, workspace=workspace_id)
25+
feed_details = get_feed_by_name(feeds=query_feeds_response, name=FEED_NAME)
26+
27+
if feed_details and feed_details.id:
28+
created_feed_name = client.delete_feed(id=feed_details.id)
29+
print("Feed deleted successfully.")
1930

2031
except ApiException as exp:
2132
print(exp)

examples/feeds/query_and_upload_feeds.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from nisystemlink.clients.core import ApiException, HttpConfiguration
44
from nisystemlink.clients.feeds._feeds_client import FeedsClient
55
from nisystemlink.clients.feeds.models import Platform
6-
from nisystemlink.clients.feeds.utilities import get_feed_id
6+
from nisystemlink.clients.feeds.utilities import get_feed_by_name
77

88
# Constant
99
FEED_NAME = "EXAMPLE FEED"
@@ -14,26 +14,24 @@
1414

1515
server_url = "" # SystemLink API URL
1616
server_api_key = "" # SystemLink API key
17-
workspace_id = "" # Systemlink workspace id
17+
workspace_id = (
18+
None # None uses Default workspace. Replace with Systemlink workspace id.
19+
)
1820

1921
# Please provide the valid API key and API URL for client intialization.
2022
client = FeedsClient(HttpConfiguration(api_key=server_api_key, server_uri=server_url))
2123

2224
# To upload a package to feed.
2325
try:
2426
# To query available feeds.
25-
query_feeds_response = client.query_feeds(
26-
platform=PLATFORM,
27-
workspace=workspace_id,
28-
)
27+
query_feeds_response = client.query_feeds(platform=PLATFORM, workspace=workspace_id)
28+
feed_details = get_feed_by_name(feeds=query_feeds_response, name=FEED_NAME)
2929

30-
feed_id = get_feed_id(feeds_details=query_feeds_response.feeds, feed_name=FEED_NAME)
31-
32-
if feed_id:
30+
if feed_details and feed_details.id:
3331
upload_package = client.upload_package(
34-
feed_id=feed_id,
32+
feed_id=feed_details.id,
3533
overwrite=True,
36-
package=open(PACKAGE_PATH, "rb"),
34+
package_file_path=PACKAGE_PATH,
3735
)
3836
print("Package uploaded sucessfully.")
3937

nisystemlink/clients/feeds/_feeds_client.py

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Implementation of SystemLink Feeds Client."""
22

3-
from typing import BinaryIO, Optional
3+
from typing import BinaryIO, List, Optional
44

55
from nisystemlink.clients import core
66
from nisystemlink.clients.core._uplink._base_client import BaseClient
@@ -63,7 +63,7 @@ def query_feeds(
6363
self,
6464
platform: Optional[models.Platform] = None,
6565
workspace: Optional[str] = None,
66-
) -> models.QueryFeedsResponse:
66+
) -> List[models.Feed]:
6767
"""Get a set of feeds based on the provided `platform` and `workspace`.
6868
6969
Args:
@@ -72,13 +72,13 @@ def query_feeds(
7272
workspace (Optional[str]): Workspace id. Defaults to None.
7373
7474
Returns:
75-
models.QueryFeedsResponse: List of feeds.
75+
List[models.Feed]: List of feeds.
7676
"""
7777
platform_by_str = platform.value if platform is not None else None
7878
response = self.__query_feeds(
7979
platform=platform_by_str,
8080
workspace=workspace,
81-
)
81+
).feeds
8282

8383
return response
8484

@@ -106,6 +106,31 @@ def __upload_package(
106106
...
107107

108108
def upload_package(
109+
self,
110+
feed_id: str,
111+
package_file_path: str,
112+
overwrite: bool = False,
113+
) -> models.Package:
114+
"""Upload package to SystemLink feed.
115+
116+
Args:
117+
feed_id (str): ID of the feed.
118+
package_file_path (str): File path of the package to be uploaded.
119+
overwrite (bool): Set to True, to overwrite the package if it already exists.\
120+
Defaults to False.
121+
122+
Returns:
123+
models.Package: Uploaded package information.
124+
"""
125+
response = self.__upload_package(
126+
feed_id=feed_id,
127+
overwrite=overwrite,
128+
package=open(package_file_path, "rb"),
129+
)
130+
131+
return response
132+
133+
def upload_package_content(
109134
self,
110135
feed_id: str,
111136
package: BinaryIO,
@@ -120,7 +145,7 @@ def upload_package(
120145
Defaults to False.
121146
122147
Returns:
123-
models.Package: Uploaded package response information.
148+
models.Package: Uploaded package information.
124149
"""
125150
response = self.__upload_package(
126151
feed_id=feed_id,
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
"""Utilities for FeedsClient."""
22

3-
from typing import List, Union
3+
from typing import List, Optional
44

55
from nisystemlink.clients.feeds.models import Feed
66

77

8-
def get_feed_id(
9-
feeds_details: List[Feed],
10-
feed_name: str,
11-
) -> Union[str, None]:
8+
def get_feed_by_name(
9+
feeds: List[Feed],
10+
name: str,
11+
) -> Optional[Feed]:
1212
"""Get feed id from the list of feed details using `feed_name`.
1313
1414
Args:
15-
feeds_details (List[Feed]): List of feed details.
15+
feeds (List[Feed]): List of feed details.
1616
feed_name (str): Feed name.
1717
1818
Returns:
19-
Union[str, None]: Feed ID of the `feed_name`.
19+
Optional[Feed]: Feed information.
2020
"""
21-
for feed in feeds_details:
22-
if feed.name == feed_name and feed.id:
23-
return feed.id
21+
for feed in feeds:
22+
if feed.name == name and feed.id:
23+
return feed
2424
return None

tests/integration/feeds/test_feeds_client.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ def test__upload_package__succeeds(
181181
client: FeedsClient,
182182
create_feed: Callable,
183183
create_feed_request: Callable,
184-
binary_pkg_file_data: BinaryIO,
185184
get_feed_name: Callable,
186185
):
187186
"""Test the case of upload package to feed."""
@@ -193,21 +192,44 @@ def test__upload_package__succeeds(
193192
create_feed_resp = create_feed(create_feed_request_body)
194193

195194
upload_pacakge_rsp = client.upload_package(
195+
package_file_path=PACKAGE_PATH,
196+
feed_id=create_feed_resp.id,
197+
overwrite=True,
198+
)
199+
assert upload_pacakge_rsp is not None
200+
201+
def test__upload_package_content__succeeds(
202+
self,
203+
client: FeedsClient,
204+
create_feed: Callable,
205+
create_feed_request: Callable,
206+
binary_pkg_file_data: BinaryIO,
207+
get_feed_name: Callable,
208+
):
209+
"""Test the case of upload package to feed."""
210+
create_feed_request_body = create_feed_request(
211+
feed_name=get_feed_name(),
212+
description=FEED_DESCRIPTION,
213+
platform=Platform.WINDOWS,
214+
)
215+
create_feed_resp = create_feed(create_feed_request_body)
216+
217+
upload_pacakge_rsp = client.upload_package_content(
196218
package=binary_pkg_file_data,
197219
feed_id=create_feed_resp.id,
198220
overwrite=True,
199221
)
200222
assert upload_pacakge_rsp is not None
201223

202-
def test__upload_package__invalid_feed_id_raises(
224+
def test__upload_package_content__invalid_feed_id_raises(
203225
self,
204226
client: FeedsClient,
205227
binary_pkg_file_data: BinaryIO,
206228
invalid_id: str,
207229
):
208230
"""Test the case of uploading package to Invalid feed."""
209231
with pytest.raises(ApiException, match="FeedNotFoundError"):
210-
client.upload_package(
232+
client.upload_package_content(
211233
package=binary_pkg_file_data,
212234
feed_id=invalid_id,
213235
)

0 commit comments

Comments
 (0)