Skip to content

Commit 22f6515

Browse files
feat: Add delete API for Artifact client (#142)
1 parent 0f58474 commit 22f6515

File tree

5 files changed

+116
-51
lines changed

5 files changed

+116
-51
lines changed

docs/api_reference.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ API Reference
1919
api_reference/assetmanagement
2020
api_reference/systems
2121
api_reference/test_plan
22+
api_reference/artifact
2223

2324
Indices and tables
2425
------------------

docs/api_reference/artifact.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.. _api_tag_page:
2+
3+
nisystemlink.clients.artifact
4+
======================
5+
6+
.. autoclass:: nisystemlink.clients.artifact.ArtifactClient
7+
:exclude-members: __init__
8+
9+
.. automethod:: __init__
10+
.. automethod:: upload_artifact
11+
.. automethod:: download_artifact
12+
.. automethod:: delete_artifact
13+
14+
.. automodule:: nisystemlink.clients.artifact.models
15+
:members:
16+
:imported-members:
Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
import io
2-
3-
from nisystemlink.clients.artifact import ArtifactClient
4-
from nisystemlink.clients.core import HttpConfiguration
5-
6-
7-
# Setup the server configuration to point to your instance of SystemLink Enterprise
8-
server_configuration = HttpConfiguration(
9-
server_uri="https://yourserver.yourcompany.com",
10-
api_key="YourAPIKeyGeneratedFromSystemLink",
11-
)
12-
client = ArtifactClient(configuration=server_configuration)
13-
14-
# Define the workspace and artifact content
15-
workspace = "your workspace ID"
16-
artifact_stream = io.BytesIO(b"test content")
17-
18-
# Upload the artifact
19-
upload_response = client.upload_artifact(workspace=workspace, artifact=artifact_stream)
20-
if upload_response and upload_response.id:
21-
print(f"Uploaded artifact ID: {upload_response.id}")
22-
23-
# Download the artifact using the ID from the upload response
24-
artifact_id = upload_response.id
25-
download_response = client.download_artifact(artifact_id)
26-
if download_response:
27-
downloaded_content = download_response.read()
28-
print(f"Downloaded artifact content: {downloaded_content.decode('utf-8')}")
1+
import io
2+
3+
from nisystemlink.clients.artifact import ArtifactClient
4+
from nisystemlink.clients.core import HttpConfiguration
5+
6+
7+
# Setup the server configuration to point to your instance of SystemLink Enterprise
8+
server_configuration = HttpConfiguration(
9+
server_uri="https://yourserver.yourcompany.com",
10+
api_key="YourAPIKeyGeneratedFromSystemLink",
11+
)
12+
client = ArtifactClient(configuration=server_configuration)
13+
14+
# Define the workspace and artifact content
15+
workspace = "your workspace ID"
16+
artifact_stream = io.BytesIO(b"test content")
17+
18+
# Upload the artifact
19+
upload_response = client.upload_artifact(workspace=workspace, artifact=artifact_stream)
20+
if upload_response and upload_response.id:
21+
print(f"Uploaded artifact ID: {upload_response.id}")
22+
23+
# Download the artifact using the ID from the upload response
24+
artifact_id = upload_response.id
25+
download_response = client.download_artifact(artifact_id)
26+
if download_response:
27+
downloaded_content = download_response.read()
28+
print(f"Downloaded artifact content: {downloaded_content.decode('utf-8')}")
29+
30+
# Delete the artifact
31+
client.delete_artifact(artifact_id)

nisystemlink/clients/artifact/_artifact_client.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44

55
from nisystemlink.clients import core
66
from nisystemlink.clients.core._uplink._base_client import BaseClient
7-
from nisystemlink.clients.core._uplink._methods import get, post, response_handler
7+
from nisystemlink.clients.core._uplink._methods import (
8+
delete,
9+
get,
10+
post,
11+
response_handler,
12+
)
813
from nisystemlink.clients.core.helpers._iterator_file_like import IteratorFileLike
914
from requests.models import Response
1015
from uplink import Part, Path
@@ -81,3 +86,13 @@ def download_artifact(self, id: Path) -> IteratorFileLike:
8186
8287
"""
8388
...
89+
90+
@delete("artifacts/{id}", args=[Path("id")])
91+
def delete_artifact(self, id: str) -> None:
92+
"""Deletes an artifact.
93+
94+
Args:
95+
id: The ID of the artifact to delete.
96+
97+
"""
98+
...
Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import io
2-
import os
2+
from typing import List
33

44
import pytest
55
from nisystemlink.clients.artifact import ArtifactClient
6+
from nisystemlink.clients.artifact.models._upload_artifact_response import (
7+
UploadArtifactResponse,
8+
)
69
from nisystemlink.clients.core._http_configuration import HttpConfiguration
710

811

@@ -12,35 +15,62 @@ def client(enterprise_config: HttpConfiguration) -> ArtifactClient:
1215
return ArtifactClient(enterprise_config)
1316

1417

18+
@pytest.fixture
19+
def create_artifact(client: ArtifactClient):
20+
"""Fixture to return a factory that creates artifact."""
21+
created_artifact_ids: List[str] = []
22+
23+
def _create_artifact(
24+
content: bytes = b"test content",
25+
cleanup: bool = True,
26+
workspace: str = "2300760d-38c4-48a1-9acb-800260812337",
27+
):
28+
# Used the main-test default workspace since the client for creating a workspace has not been added yet
29+
artifact_stream = io.BytesIO(content)
30+
response = client.upload_artifact(workspace=workspace, artifact=artifact_stream)
31+
if cleanup:
32+
created_artifact_ids.append(response.id)
33+
34+
return response
35+
36+
yield _create_artifact
37+
38+
for artifact_id in created_artifact_ids:
39+
client.delete_artifact(artifact_id)
40+
41+
1542
@pytest.mark.integration
1643
@pytest.mark.enterprise
1744
class TestArtifact:
1845

19-
def test__upload_artifact__artifact_uploaded(self, client: ArtifactClient):
20-
workspace = os.getenv("SYSTEMLINK_WORKSPACE_ID")
46+
def test__upload_artifact__artifact_uploaded(
47+
self, client: ArtifactClient, create_artifact
48+
):
49+
upload_response: UploadArtifactResponse = create_artifact()
2150

22-
if workspace is not None:
23-
artifact_stream = io.BytesIO(b"test content")
51+
assert upload_response is not None
52+
assert upload_response.id is not None
2453

25-
response = client.upload_artifact(
26-
workspace=workspace, artifact=artifact_stream
27-
)
54+
def test__download_artifact__artifact_downloaded(
55+
self, client: ArtifactClient, create_artifact
56+
):
57+
artifact_content = b"test content"
2858

29-
assert response is not None
30-
assert response.id is not None
59+
upload_response: UploadArtifactResponse = create_artifact(
60+
content=artifact_content
61+
)
62+
artifact_id = upload_response.id
63+
download_response = client.download_artifact(artifact_id)
3164

32-
def test__download_artifact__artifact_downloaded(self, client: ArtifactClient):
33-
workspace = os.getenv("SYSTEMLINK_WORKSPACE_ID")
65+
assert download_response is not None
66+
assert download_response.read() == artifact_content
3467

35-
if workspace is not None:
36-
artifact_content = b"test content"
37-
artifact_stream = io.BytesIO(artifact_content)
68+
def test__delete_artifact__artifact_deleted(
69+
self, client: ArtifactClient, create_artifact
70+
):
71+
upload_response: UploadArtifactResponse = create_artifact(cleanup=False)
72+
artifact_id = upload_response.id
3873

39-
upload_response = client.upload_artifact(
40-
workspace=workspace, artifact=artifact_stream
41-
)
42-
artifact_id = upload_response.id
43-
download_response = client.download_artifact(artifact_id)
74+
delete_response = client.delete_artifact(artifact_id)
4475

45-
assert download_response is not None
46-
assert download_response.read() == artifact_content
76+
assert delete_response is None

0 commit comments

Comments
 (0)