1313TEST_URL = "https://api.revenera.com"
1414TEST_API_TOKEN = "your_api_token"
1515
16+
1617class 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+
3335class 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
0 commit comments