Skip to content

Commit 5993f4a

Browse files
authored
Merge pull request #16 from zkarpinski/deepsource-transform-94bd8161
style: format code with Black
2 parents ab5c48f + ecdf270 commit 5993f4a

11 files changed

Lines changed: 108 additions & 67 deletions

File tree

codeinsight_sdk/exceptions.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
21
import requests
32
import json
43

5-
class GenericError(Exception): #pragma: no cover
4+
5+
class GenericError(Exception): # pragma: no cover
66
"""Generic error class, catch-all for most code insight API errors."""
7+
78
pass
89

9-
class NotYetImplementedError(Exception): #pragma: no cover
10+
11+
class NotYetImplementedError(Exception): # pragma: no cover
1012
"""Error class for API features that have not yet been implemented."""
13+
1114
pass
1215

16+
1317
class CodeInsightError(GenericError):
1418
"""Error class for code insight API errors."""
19+
1520
def __init__(self, response: requests.Response):
1621
try:
1722
resp = response.json()
1823
self.code = response.status_code
19-
self.message = resp['Error: ']
20-
self.arguments = resp['Arguments: ']
21-
self.error = resp['Key: ']
24+
self.message = resp["Error: "]
25+
self.arguments = resp["Arguments: "]
26+
self.error = resp["Key: "]
2227
self.add_note(f"Arguments: {self.arguments}")
2328
super().__init__("Error: %s - %s" % (self.code, self.message))
2429

codeinsight_sdk/handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List
33

44

5+
56
class Handler(abc.ABC):
67
def __init__(self, client):
78
self.client = client
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .inventory import InventoryHandler
22
from .project import ProjectHandler
3-
from .report import ReportHandler
3+
from .report import ReportHandler

codeinsight_sdk/handlers/report.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self, client):
2222
super().__init__(client)
2323
self.cls = Report
2424

25-
def get(self, id:int):
25+
def get(self, id: int):
2626
"""
2727
Retrieves a report by its ID.
2828
@@ -35,7 +35,7 @@ def get(self, id:int):
3535
"""
3636
path = f"reports/{id}"
3737
resp = self.client.request("GET", url_part=path)
38-
report_data = resp.json()['data']
38+
report_data = resp.json()["data"]
3939
report = self.cls.from_dict(report_data)
4040
return report
4141

@@ -50,6 +50,6 @@ def all(self):
5050
path = "reports"
5151
resp = self.client.request("GET", url_part=path)
5252
reports = []
53-
for report_data in resp.json()['data']:
53+
for report_data in resp.json()["data"]:
5454
reports.append(self.cls.from_dict(report_data))
5555
return reports

codeinsight_sdk/models.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from dataclasses_json import DataClassJsonMixin, dataclass_json
66
from typing import Any, Optional, List, Dict
77

8+
89
@dataclass
910
class Project(DataClassJsonMixin):
1011
id: int
@@ -26,6 +27,7 @@ class Vulnerability(DataClassJsonMixin):
2627
vulnerabilityCvssV3Score: int
2728
vulnerabilityCvssV3Severity: str
2829

30+
2931
@dataclass
3032
class ProjectInventoryItem(DataClassJsonMixin):
3133
itemNumber: int
@@ -45,12 +47,14 @@ class ProjectInventoryItem(DataClassJsonMixin):
4547
vulnerabilitySummary: Optional[List[Dict[str, Dict]]] = None
4648
filePaths: Optional[List[str]] = None
4749

48-
@dataclass_json #Trying this style instead of DataClassJsonMixin
50+
51+
@dataclass_json # Trying this style instead of DataClassJsonMixin
4952
@dataclass
50-
class ProjectInventory():
53+
class ProjectInventory:
5154
projectId: int
5255
inventoryItems: List[ProjectInventoryItem]
5356

57+
5458
@dataclass
5559
class Report(DataClassJsonMixin):
5660
id: int
@@ -61,4 +65,4 @@ class Report(DataClassJsonMixin):
6165
enableProjectPicker: bool
6266
order: int
6367
createdDateTime: str
64-
updatedDateTime: str
68+
updatedDateTime: str

examples/example-1-list-projects.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88

99

1010
print(client.projects.all())
11-

examples/example-9-dataframe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99

1010
inventory = client.project_inventory.get(1)
11-
df = pd.DataFrame(inventory.__dict__['inventoryItems'])
11+
df = pd.DataFrame(inventory.__dict__["inventoryItems"])

examples/shared.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
2-
BASE_URL = 'https://api.revenera.com'
3-
AUTH_TOKEN = 'test'
1+
BASE_URL = "https://api.revenera.com"
2+
AUTH_TOKEN = "test"

tests/test_client.py

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
TEST_URL = "https://api.revenera.com"
1414
TEST_API_TOKEN = "your_api_token"
1515

16+
1617
class TestCodeInsightClient:
1718
@pytest.fixture
1819
def client(self):
1920
return CodeInsightClient(TEST_URL, TEST_API_TOKEN)
20-
21+
2122
def test_client(self, client):
2223
assert client.base_url == TEST_URL
23-
24+
2425
def test_client_expertimental_disabled(self, client):
2526
assert client.experimental_enabled == False
2627

@@ -30,44 +31,54 @@ def test_endpoint_not_found(self, client):
3031
with pytest.raises(Exception):
3132
client.projects.all()
3233

34+
3335
class TestProjectEndpoints:
3436
@pytest.fixture
3537
def client(self):
3638
return CodeInsightClient(TEST_URL, TEST_API_TOKEN)
37-
39+
3840
def test_create_project(self, client):
3941
project_name = "Test"
4042
with requests_mock.Mocker() as m:
4143
m.post(f"{TEST_URL}/codeinsight/api/projects", text='{"data": {"id":1}}')
4244
project_id = client.projects.create(project_name)
4345
assert project_id == 1
44-
46+
4547
def test_get_all_projects(self, client):
4648
with requests_mock.Mocker() as m:
47-
m.get(f"{TEST_URL}/codeinsight/api/projects", text='{"data": [{"id":1, "name":"Test"}, {"id":2, "name":"Test 2"}]}')
49+
m.get(
50+
f"{TEST_URL}/codeinsight/api/projects",
51+
text='{"data": [{"id":1, "name":"Test"}, {"id":2, "name":"Test 2"}]}',
52+
)
4853
projects = client.projects.all()
4954
assert len(projects) > 0
5055

5156
def test_get_project_id(self, client):
5257
project_name = "Test"
5358
with requests_mock.Mocker() as m:
54-
m.get(f"{TEST_URL}/codeinsight/api/project/id", text='{ "Content: ": 1 }') # Yes, the key is called 'Content: ' ...
59+
m.get(
60+
f"{TEST_URL}/codeinsight/api/project/id", text='{ "Content: ": 1 }'
61+
) # Yes, the key is called 'Content: ' ...
5562
project_id = client.projects.get_id(project_name)
5663
assert project_id == 1
5764

58-
def test_get_project_id_invalid(self,client):
65+
def test_get_project_id_invalid(self, client):
5966
project_name = "Invalid_Project"
6067
fake_response_json = """{ "Arguments: " : ["",""],
6168
"Key: ": " InvalidProjectNameParm",
6269
"Error: ": "The project name entered was not found" }
6370
"""
6471
with requests_mock.Mocker() as m:
65-
# Note, the key names end with a colon and space '...: '
66-
m.get(f"{TEST_URL}/codeinsight/api/project/id", text=fake_response_json, status_code=400)
72+
# Note, the key names end with a colon and space '...: '
73+
m.get(
74+
f"{TEST_URL}/codeinsight/api/project/id",
75+
text=fake_response_json,
76+
status_code=400,
77+
)
6778
with pytest.raises(CodeInsightError):
6879
client.projects.get_id(project_name)
69-
70-
def test_get_project(self,client):
80+
81+
def test_get_project(self, client):
7182
project_id = 1
7283
fake_response_json = """ { "data": {
7384
"id": 1,
@@ -96,7 +107,10 @@ def test_get_project(self,client):
96107
}}
97108
"""
98109
with requests_mock.Mocker() as m:
99-
m.get(f"{TEST_URL}/codeinsight/api/projects/{project_id}", text=fake_response_json)
110+
m.get(
111+
f"{TEST_URL}/codeinsight/api/projects/{project_id}",
112+
text=fake_response_json,
113+
)
100114
project = client.projects.get(project_id)
101115
assert project.id == 1
102116
assert project.name == "Test"
@@ -105,7 +119,7 @@ def test_get_project(self,client):
105119
assert project.vulnerabilities["CvssV2"]["High"] == 2
106120
assert project.vulnerabilities["CvssV2"]["Unknown"] == 4
107121

108-
def test_get_project_inventory_multipage(self,client):
122+
def test_get_project_inventory_multipage(self, client):
109123
project_id = 1
110124
total_pages = 4
111125
total_records = total_pages * 2
@@ -121,23 +135,32 @@ def test_get_project_inventory_multipage(self,client):
121135
]}
122136
"""
123137
with requests_mock.Mocker() as m:
124-
m.get(f"{TEST_URL}/codeinsight/api/project/inventory/{project_id}",
125-
text=fake_response_json, headers=response_header)
138+
m.get(
139+
f"{TEST_URL}/codeinsight/api/project/inventory/{project_id}",
140+
text=fake_response_json,
141+
headers=response_header,
142+
)
126143
project_inventory = client.projects.get_inventory(project_id)
127144
assert project_inventory.projectId == project_id
128145
assert len(project_inventory.inventoryItems) == total_records
129-
assert project_inventory.inventoryItems[0].vulnerabilities[0].vulnerabilityName == "CVE-2020-1234"
130-
131-
def test_upload_codebase(self,client):
146+
assert (
147+
project_inventory.inventoryItems[0].vulnerabilities[0].vulnerabilityName
148+
== "CVE-2020-1234"
149+
)
150+
151+
def test_upload_codebase(self, client):
132152
project_id = 1
133153
codebase_path = "tests/resources/test_codebase.zip"
134154
with requests_mock.Mocker() as m:
135-
m.post(f"{TEST_URL}/codeinsight/api/project/uploadProjectCodebase", text='{"data": {"id":1}}')
155+
m.post(
156+
f"{TEST_URL}/codeinsight/api/project/uploadProjectCodebase",
157+
text='{"data": {"id":1}}',
158+
)
136159
resp = client.projects.upload_codebase(project_id, codebase_path)
137160
assert resp == 200
138161

139162
#### FIX THIS! ####
140-
def test_get_project_inventory_summary(self,client):
163+
def test_get_project_inventory_summary(self, client):
141164
project_id = 1
142165
total_pages = 4
143166
total_records = total_pages * 2
@@ -174,9 +197,14 @@ def test_get_project_inventory_summary(self,client):
174197
}
175198
"""
176199
with requests_mock.Mocker() as m:
177-
m.get(f"{TEST_URL}/codeinsight/api/projects/{project_id}/inventorySummary",
178-
text=fake_response_json, headers=response_header)
179-
project_inventory_summary = client.projects.get_inventory_summary(project_id)
200+
m.get(
201+
f"{TEST_URL}/codeinsight/api/projects/{project_id}/inventorySummary",
202+
text=fake_response_json,
203+
headers=response_header,
204+
)
205+
project_inventory_summary = client.projects.get_inventory_summary(
206+
project_id
207+
)
180208

181209
assert len(project_inventory_summary) == 8
182210
assert project_inventory_summary[1].id == 12346
@@ -186,8 +214,8 @@ class TestReportsEndpoints:
186214
@pytest.fixture
187215
def client(self):
188216
return CodeInsightClient(TEST_URL, TEST_API_TOKEN)
189-
190-
def test_get_reports_all(self,client):
217+
218+
def test_get_reports_all(self, client):
191219
fake_response_json = """ { "data": [
192220
{
193221
"id": 1,
@@ -216,14 +244,13 @@ def test_get_reports_all(self,client):
216244
}
217245
"""
218246
with requests_mock.Mocker() as m:
219-
m.get(f"{TEST_URL}/codeinsight/api/reports",
220-
text=fake_response_json)
247+
m.get(f"{TEST_URL}/codeinsight/api/reports", text=fake_response_json)
221248
reports = client.reports.all()
222249
assert len(reports) == 2
223250
assert reports[1].id == 2
224251
assert reports[1].enabled == False
225252

226-
def test_get_report(self,client):
253+
def test_get_report(self, client):
227254
report_id = 1
228255
fake_response_json = """ { "data":
229256
{
@@ -240,8 +267,10 @@ def test_get_report(self,client):
240267
}
241268
"""
242269
with requests_mock.Mocker() as m:
243-
m.get(f"{TEST_URL}/codeinsight/api/reports/{report_id}",
244-
text=fake_response_json)
270+
m.get(
271+
f"{TEST_URL}/codeinsight/api/reports/{report_id}",
272+
text=fake_response_json,
273+
)
245274
report = client.reports.get(1)
246275
assert report.id == 1
247-
assert report.enabled == True
276+
assert report.enabled == True

tests/test_models.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,33 @@
22

33
from codeinsight_sdk.models import Project, Report
44

5+
56
class TestProject(object):
67
@pytest.fixture
78
def project(self):
89
return Project(id=1, name="Test")
9-
10+
1011
def test_project(self, project):
1112
assert project.id == 1
1213
assert project.name == "Test"
1314
assert isinstance(project, Project)
14-
15+
16+
1517
class TestReport(object):
1618
@pytest.fixture
1719
def report(self):
18-
return Report(id=1,
19-
name="Test",
20-
path="path/to/report",
21-
default=True,
22-
enabled=True,
23-
enableProjectPicker=True,
24-
order=1,
25-
createdDateTime="Today",
26-
updatedDateTime="Tomorrow")
27-
20+
return Report(
21+
id=1,
22+
name="Test",
23+
path="path/to/report",
24+
default=True,
25+
enabled=True,
26+
enableProjectPicker=True,
27+
order=1,
28+
createdDateTime="Today",
29+
updatedDateTime="Tomorrow",
30+
)
31+
2832
def test_report(self, report):
2933
assert report.id == 1
3034
assert report.enabled == True

0 commit comments

Comments
 (0)