Skip to content

Commit 18b1212

Browse files
committed
Fix cached scan CI coverage
Exercise the cached stream through the real SDK transport and bump the package version to an unpublished release. Assisted-by: Codex: GPT-6
1 parent 97d148a commit 18b1212

2 files changed

Lines changed: 30 additions & 22 deletions

File tree

‎socketdev/version.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "3.6.0"
1+
__version__ = "3.7.0"

‎tests/unit/test_socket_purl_type.py‎

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
import logging
2222
import unittest
2323

24+
from socketdev import socketdev
2425
from socketdev.fullscans import (
25-
FullScans,
2626
FullScanStreamResponse,
2727
SocketArtifact,
2828
SocketPURL,
2929
SocketPURL_Type,
3030
)
31+
from tests.support.socket_api_fixture import SocketApiFixture, SocketResponse
3132

3233

3334
def _artifact_payload(artifact_id: str, purl_type: str) -> dict:
@@ -109,32 +110,39 @@ def test_malformed_artifact_is_skipped_not_fatal(self):
109110
)
110111

111112
def test_full_scans_stream_skips_artifact_without_id(self):
112-
class Response:
113-
status_code = 200
114-
text = "\n".join(
113+
fixture = SocketApiFixture()
114+
fixture.start()
115+
try:
116+
body = "\n".join(
115117
json.dumps(artifact)
116118
for artifact in (
117119
_artifact_payload("good", "npm"),
118120
{"type": "npm", "name": "bad", "alerts": []},
119121
)
122+
).encode("utf-8")
123+
fixture.route(
124+
"GET",
125+
"orgs/org/full-scans/scan",
126+
SocketResponse(200, None, raw_body=body),
120127
)
121-
122-
class API:
123-
def do_request(self, **kwargs):
124-
return Response()
125-
126-
with self.assertLogs("socketdev", level=logging.WARNING) as captured:
127-
response = FullScans(API()).stream("org", "scan", use_types=True)
128-
129-
self.assertTrue(response.success)
130-
self.assertEqual(list(response.artifacts), ["good"])
131-
self.assertTrue(
132-
any(
133-
"Skipping artifact without a usable id" in message
134-
for message in captured.output
135-
),
136-
f"expected a warning about the skipped artifact, got: {captured.output}",
137-
)
128+
sdk = socketdev(token="synthetic-token", timeout=1)
129+
sdk.api.api_url = fixture.base_url
130+
131+
with self.assertLogs("socketdev", level=logging.WARNING) as captured:
132+
response = sdk.fullscans.stream("org", "scan", use_types=True)
133+
134+
self.assertTrue(response.success)
135+
self.assertEqual(list(response.artifacts), ["good"])
136+
self.assertTrue(
137+
any(
138+
"Skipping artifact without a usable id" in message
139+
for message in captured.output
140+
),
141+
f"expected a warning about the skipped artifact, got: {captured.output}",
142+
)
143+
self.assertEqual(fixture.requests[0].query, {"cached": ["true"]})
144+
finally:
145+
fixture.close()
138146

139147

140148
if __name__ == "__main__":

0 commit comments

Comments
 (0)