Skip to content

Commit 56ad57e

Browse files
authored
Merge pull request #111 from zkarpinski/feat/full-mocking-support-7041241834180989467
feat: Add full mocking support and missing endpoints
2 parents 076b0c5 + 32eecdb commit 56ad57e

17 files changed

Lines changed: 577 additions & 79 deletions

codeinsight_sdk/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@
1616
"""
1717

1818
from .client import CodeInsightClient
19+
20+
# Optional mocking support
21+
try:
22+
from .testing import CodeInsightMockAdapter, mock_client, codeinsight_mock
23+
except ImportError:
24+
pass

codeinsight_sdk/client.py

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,31 +92,56 @@ def experimental(self) -> ExperimentalHandler:
9292
raise CodeInsightError("Experimental API is not enabled for this instance")
9393
return ExperimentalHandler(self)
9494

95-
# Coming soon...?
95+
@property
96+
def vulnerabilities(self):
97+
from .handlers import VulnerabilityHandler
9698

97-
def vulnerabilites(self):
98-
raise NotImplementedError
99+
return VulnerabilityHandler(self)
99100

101+
@property
100102
def users(self):
101-
raise NotImplementedError
103+
from .handlers import UserHandler
104+
105+
return UserHandler(self)
102106

107+
@property
103108
def licenses(self):
104-
raise NotImplementedError
109+
from .handlers import LicenseHandler
110+
111+
return LicenseHandler(self)
105112

113+
@property
106114
def tasks(self):
107-
raise NotImplementedError
115+
from .handlers import TaskHandler
116+
117+
return TaskHandler(self)
108118

119+
@property
109120
def rules(self):
110-
raise NotImplementedError
121+
from .handlers import RuleHandler
122+
123+
return RuleHandler(self)
111124

125+
@property
112126
def files(self):
113-
raise NotImplementedError
127+
from .handlers import FileHandler
128+
129+
return FileHandler(self)
114130

131+
@property
115132
def folders(self):
116-
raise NotImplementedError
133+
from .handlers import FolderHandler
134+
135+
return FolderHandler(self)
117136

137+
@property
118138
def jobs(self):
119-
raise NotImplementedError
139+
from .handlers import JobHandler
140+
141+
return JobHandler(self)
120142

143+
@property
121144
def components(self):
122-
raise NotImplementedError
145+
from .handlers import ComponentHandler
146+
147+
return ComponentHandler(self)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
from .inventory import InventoryHandler
22
from .project import ProjectHandler
33
from .report import ReportHandler
4+
from .vulnerability import VulnerabilityHandler
5+
from .user import UserHandler
6+
from .license import LicenseHandler
7+
from .task import TaskHandler
8+
from .rule import RuleHandler
9+
from .file import FileHandler
10+
from .folder import FolderHandler
11+
from .job import JobHandler
12+
from .component import ComponentHandler
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import Component
4+
5+
6+
class ComponentHandler(Handler):
7+
def all(self) -> List[Component]:
8+
"""
9+
Retrieves all components.
10+
"""
11+
path = "components"
12+
resp = self.client.request("GET", url_part=path)
13+
return [Component.from_dict(component) for component in resp.json()["data"]]
14+
15+
def get(self, id: int) -> Component:
16+
"""
17+
Retrieves a component by its ID.
18+
"""
19+
path = f"components/{id}"
20+
resp = self.client.request("GET", url_part=path)
21+
return Component.from_dict(resp.json()["data"])

codeinsight_sdk/handlers/file.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import File
4+
5+
6+
class FileHandler(Handler):
7+
def get(self, id: int) -> File:
8+
"""
9+
Retrieves a file by its ID.
10+
"""
11+
path = f"files/{id}"
12+
resp = self.client.request("GET", url_part=path)
13+
return File.from_dict(resp.json()["data"])

codeinsight_sdk/handlers/folder.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import Folder
4+
5+
6+
class FolderHandler(Handler):
7+
def get(self, id: int) -> Folder:
8+
"""
9+
Retrieves a folder by its ID.
10+
"""
11+
path = f"folders/{id}"
12+
resp = self.client.request("GET", url_part=path)
13+
return Folder.from_dict(resp.json()["data"])

codeinsight_sdk/handlers/job.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import Job
4+
5+
6+
class JobHandler(Handler):
7+
def all(self) -> List[Job]:
8+
"""
9+
Retrieves all jobs.
10+
"""
11+
path = "jobs"
12+
resp = self.client.request("GET", url_part=path)
13+
return [Job.from_dict(job) for job in resp.json()["data"]]
14+
15+
def get(self, id: int) -> Job:
16+
"""
17+
Retrieves a job by its ID.
18+
"""
19+
path = f"jobs/{id}"
20+
resp = self.client.request("GET", url_part=path)
21+
return Job.from_dict(resp.json()["data"])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import License
4+
5+
6+
class LicenseHandler(Handler):
7+
def all(self) -> List[License]:
8+
"""
9+
Retrieves all licenses.
10+
"""
11+
path = "licenses"
12+
resp = self.client.request("GET", url_part=path)
13+
return [License.from_dict(license) for license in resp.json()["data"]]
14+
15+
def get(self, id: int) -> License:
16+
"""
17+
Retrieves a license by its ID.
18+
"""
19+
path = f"licenses/{id}"
20+
resp = self.client.request("GET", url_part=path)
21+
return License.from_dict(resp.json()["data"])

codeinsight_sdk/handlers/rule.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import Rule
4+
5+
6+
class RuleHandler(Handler):
7+
def all(self) -> List[Rule]:
8+
"""
9+
Retrieves all rules.
10+
"""
11+
path = "rules"
12+
resp = self.client.request("GET", url_part=path)
13+
return [Rule.from_dict(rule) for rule in resp.json()["data"]]
14+
15+
def get(self, id: int) -> Rule:
16+
"""
17+
Retrieves a rule by its ID.
18+
"""
19+
path = f"rules/{id}"
20+
resp = self.client.request("GET", url_part=path)
21+
return Rule.from_dict(resp.json()["data"])

codeinsight_sdk/handlers/task.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
from ..handler import Handler
3+
from ..models import Task
4+
5+
6+
class TaskHandler(Handler):
7+
def all(self) -> List[Task]:
8+
"""
9+
Retrieves all tasks.
10+
"""
11+
path = "tasks"
12+
resp = self.client.request("GET", url_part=path)
13+
return [Task.from_dict(task) for task in resp.json()["data"]]
14+
15+
def get(self, id: int) -> Task:
16+
"""
17+
Retrieves a task by its ID.
18+
"""
19+
path = f"tasks/{id}"
20+
resp = self.client.request("GET", url_part=path)
21+
return Task.from_dict(resp.json()["data"])

0 commit comments

Comments
 (0)