@@ -26,8 +26,12 @@ def test_endpoint_not_found(self, client):
2626 m .get (f"{ TEST_URL } /codeinsight/api/projects" , status_code = 404 )
2727 with pytest .raises (Exception ):
2828 client .projects .all ()
29-
30-
29+
30+ class TestProjectEndpoints :
31+ @pytest .fixture
32+ def client (self ):
33+ return CodeInsightClient (TEST_URL , TEST_API_TOKEN )
34+
3135 def test_get_all_projects (self , client ):
3236 with requests_mock .Mocker () as m :
3337 m .get (f"{ TEST_URL } /codeinsight/api/projects" , text = '{"data": [{"id":1, "name":"Test"}, {"id":2, "name":"Test 2"}]}' )
@@ -46,9 +50,9 @@ def test_get_project_id_invalid(self,client):
4650 fake_response_json = """{ "Arguments: " : ["",""],
4751 "Key: ": " InvalidProjectNameParm",
4852 "Error: ": "The project name entered was not found" }
49- """
53+ """
5054 with requests_mock .Mocker () as m :
51- # Note, the key names end with a colon and space '...: '
55+ # Note, the key names end with a colon and space '...: '
5256 m .get (f"{ TEST_URL } /codeinsight/api/project/id" , text = fake_response_json , status_code = 400 )
5357 with pytest .raises (CodeInsightError ):
5458 client .projects .get_id (project_name )
@@ -91,24 +95,37 @@ def test_get_project(self,client):
9195 assert project .vulnerabilities ["CvssV2" ]["High" ] == 2
9296 assert project .vulnerabilities ["CvssV2" ]["Unknown" ] == 4
9397
94- def test_get_project_inventory (self ,client ):
98+ def test_get_project_inventory_multipage (self ,client ):
9599 project_id = 1
100+ total_pages = 4
101+ total_records = total_pages * 2
102+ response_header = {"content-type" : "application/json" }
103+ response_header ["current-page" ] = "1"
104+ response_header ["number-of-pages" ] = str (total_pages )
105+ response_header ["total-records" ] = str (total_records )
106+
96107 fake_response_json = """
97- { "projectId": 1, "inventoryItems": [
98- {"itemNumber":1, "id":1234, "name":"Example component","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"},
99- {"itemNumber":2, "id":1235, "name":"Example component 2","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"}
100- ]}
101- """
108+ { "projectId": 1, "inventoryItems": [
109+ {"itemNumber":1, "id":1234, "name":"Example component","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"},
110+ {"itemNumber":2, "id":1235, "name":"Example component 2","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"}
111+ ]}
112+ """
102113 with requests_mock .Mocker () as m :
103114 m .get (f"{ TEST_URL } /codeinsight/api/project/inventory/{ project_id } " ,
104- text = fake_response_json )
105- projectInventory = client .projects .get_inventory (project_id )
106- assert projectInventory .projectId == project_id
107- assert len (projectInventory .inventoryItems ) >= 2
115+ text = fake_response_json , headers = response_header )
116+ project_inventory = client .projects .get_inventory (project_id )
117+ assert project_inventory .projectId == project_id
118+ assert len (project_inventory .inventoryItems ) == total_records
108119
109120 #### FIX THIS! ####
110121 def test_get_project_inventory_summary (self ,client ):
111122 project_id = 1
123+ total_pages = 4
124+ total_records = total_pages * 2
125+ response_header = {"content-type" : "application/json" }
126+ response_header ["current-page" ] = "1"
127+ response_header ["number-of-pages" ] = str (total_pages )
128+ response_header ["total-records" ] = str (total_records )
112129 fake_response_json = """ { "data": [
113130 {
114131 "itemNumber": 1,
@@ -140,12 +157,17 @@ def test_get_project_inventory_summary(self,client):
140157 """
141158 with requests_mock .Mocker () as m :
142159 m .get (f"{ TEST_URL } /codeinsight/api/projects/{ project_id } /inventorySummary" ,
143- text = fake_response_json )
160+ text = fake_response_json , headers = response_header )
144161 project_inventory_summary = client .projects .get_inventory_summary (project_id )
145162
146- assert len (project_inventory_summary ) == 2
163+ assert len (project_inventory_summary ) == 8
147164 assert project_inventory_summary [1 ].id == 12346
148165
166+ class TestReportsEndpoints :
167+ @pytest .fixture
168+ def client (self ):
169+ return CodeInsightClient (TEST_URL , TEST_API_TOKEN )
170+
149171 def test_get_reports_all (self ,client ):
150172 fake_response_json = """ { "data": [
151173 {
@@ -203,5 +225,4 @@ def test_get_report(self,client):
203225 text = fake_response_json )
204226 report = client .reports .get (1 )
205227 assert report .id == 1
206- assert report .enabled == True
207-
228+ assert report .enabled == True
0 commit comments