Skip to content

Commit

Permalink
feat: add delete feed api
Browse files Browse the repository at this point in the history
  • Loading branch information
Giriharan219 committed Oct 24, 2024
1 parent d6df109 commit 927fb47
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/feeds/create_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
created_feed_name = client.create_feed(feed=feed_request).name

print("Feeds created Successfully.")
print("Feed created Successfully.")
print(f"Created feed name: {created_feed_name}")

except ApiException as exp:
Expand Down
23 changes: 23 additions & 0 deletions examples/feeds/delete_feed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Functionality of deleting feed API."""

from nisystemlink.clients.core import ApiException, HttpConfiguration
from nisystemlink.clients.feeds._feeds_client import FeedsClient


FEED_ID = ""

server_url = "" # SystemLink API URL
server_api_key = "" # SystemLink API key

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

# Deleting Feed.
try:
created_feed_name = client.delete_feed(feed_id=FEED_ID)
print("Feed deleted successfully.")

except ApiException as exp:
print(exp)
except Exception as exp:
print(exp)
17 changes: 16 additions & 1 deletion nisystemlink/clients/feeds/_feeds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from nisystemlink.clients import core
from nisystemlink.clients.core._uplink._base_client import BaseClient
from nisystemlink.clients.core._uplink._methods import get, post
from nisystemlink.clients.core._uplink._methods import delete, get, post
from uplink import Part, Path, Query

from . import models
Expand Down Expand Up @@ -84,3 +84,18 @@ def upload_package(
models.UploadPackageResponse: Uploaded package response information.
"""
...

@delete(
"feeds/{feedId}",
args=[Path(name="feedId")],
)
def delete_feed(self, feed_id: str) -> None:
"""Delete feed and its packages.
Args:
feed_id (str): ID of the feed to be deleted.
Returns:
None.
"""
...
38 changes: 29 additions & 9 deletions tests/integration/feeds/test_feeds_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from nisystemlink.clients.feeds.models import CreateFeedRequest, Platform


WINDOWS_FEED_NAME = "Sample Feed"
LINUX_FEED_NAME = "Test Feed"
WINDOWS_FEED_NAME = "Windows Feed"
LINUX_FEED_NAME = "Linux Feed"
FEED_DESCRIPTION = "Sample feed for uploading packages"
INVALID_WORKSPACE_ID = "12345"
PACKAGE_PATH = (
Expand Down Expand Up @@ -69,15 +69,25 @@ def _create_feed_request():


@pytest.fixture(scope="class")
def get_feed_id(client: FeedsClient):
"""Fixture to return the Feed ID of the created new feed."""
def get_windows_feed_id(client: FeedsClient):
"""Fixture to return the Feed ID of the created windows feed."""
query_feeds_response = client.query_feeds(platform=Platform.WINDOWS.value)

for feed in query_feeds_response.feeds:
if feed.name == WINDOWS_FEED_NAME:
return feed.id


@pytest.fixture(scope="class")
def get_linux_feed_id(client: FeedsClient):
"""Fixture to return the Feed ID of the created Linux feed."""
query_feeds_response = client.query_feeds(platform=Platform.NI_LINUX_RT.value)

for feed in query_feeds_response.feeds:
if feed.name == LINUX_FEED_NAME:
return feed.id


@pytest.mark.enterprise
@pytest.mark.integration
class TestFeedsClient:
Expand Down Expand Up @@ -119,7 +129,7 @@ def test__query_feeds_windows_platform(self, client: FeedsClient):
assert response is not None

def test__query_feeds_linux_platform(self, client: FeedsClient):
"""Test the case for querying available feeds for Linux platform."""
"""Test the case for querying available feeds for linux platform."""
response = client.query_feeds(platform=Platform.NI_LINUX_RT.value)
assert response is not None

Expand All @@ -128,14 +138,24 @@ def test__query_feeds_invalid_workspace(self, client: FeedsClient):
with pytest.raises(ApiException, match="UnauthorizedWorkspaceError"):
client.query_feeds(workspace=INVALID_WORKSPACE_ID)

def test__upload_package(self, client: FeedsClient, get_feed_id: str):
def test__upload_package(self, client: FeedsClient, get_windows_feed_id: str):
"""Test the case of upload package to feed."""
response = client.upload_package(
package=open(PACKAGE_PATH, "rb"), feed_id=get_feed_id
package=open(PACKAGE_PATH, "rb"), feed_id=get_windows_feed_id, overwrite=True
)
assert response is not None

def test__upload_duplicate_package(self, client: FeedsClient, get_feed_id: str):
def test__upload_duplicate_package(self, client: FeedsClient, get_windows_feed_id: str):
"""Test the case of uploading duplicate package to feed."""
with pytest.raises(ApiException, match="DuplicatePackageError"):
client.upload_package(package=open(PACKAGE_PATH, "rb"), feed_id=get_feed_id)
client.upload_package(package=open(PACKAGE_PATH, "rb"), feed_id=get_windows_feed_id)

def test__delete__windows_feed(self, client: FeedsClient, get_windows_feed_id: str):
"""Test the case of deleting windows feed with its packages."""
response = client.delete_feed(feed_id=get_windows_feed_id)
assert response is None

def test__delete__linux_feed(self, client: FeedsClient, get_linux_feed_id: str):
"""Test the case of deleting linux feed with its packages."""
response = client.delete_feed(feed_id=get_linux_feed_id)
assert response is None

0 comments on commit 927fb47

Please sign in to comment.