@@ -33,35 +33,103 @@ def test_get_all_projects(self, client):
3333 projects = client .projects .all ()
3434 assert len (projects ) > 0
3535
36- def test_get_project (self ,client ):
36+ def test_get_project_id (self ,client ):
3737 projectName = "Test"
3838 with requests_mock .Mocker () as m :
3939 m .get (f"{ TEST_URL } /codeinsight/api/project/id" , text = '{ "Content": 1 }' )
4040 project_id = client .projects .get_id (projectName )
4141 assert project_id == 1
42+
43+ def test_get_project (self ,client ):
44+ project_id = 1
45+ fake_response_json = """ { "data": {
46+ "id": 1,
47+ "name": "Test",
48+ "description": "Test project",
49+ "createdBy": "Zach",
50+ "createdOn": "Today",
51+ "updatedOn": "Tomorrow",
52+ "projectType": "maven",
53+ "projectUrl": "",
54+ "vulnerabilities": {
55+ "CvssV2": {
56+ "High": 2,
57+ "Medium": 2,
58+ "Low": 3,
59+ "Unknown": 4
60+ },
61+ "CvssV3": {
62+ "Critical": 1,
63+ "High": 1,
64+ "Medium": 2,
65+ "Low": 6,
66+ "Unknown": 1
67+ }
68+ }
69+ }}
70+ """
71+ with requests_mock .Mocker () as m :
72+ m .get (f"{ TEST_URL } /codeinsight/api/projects/{ project_id } " , text = fake_response_json )
73+ project = client .projects .get (project_id )
74+ assert project .id == 1
75+ assert project .name == "Test"
76+ assert project .vulnerabilities ["CvssV3" ]["Critical" ] == 1
77+ assert project .vulnerabilities ["CvssV3" ]["High" ] == 1
78+ assert project .vulnerabilities ["CvssV2" ]["High" ] == 2
79+ assert project .vulnerabilities ["CvssV2" ]["Unknown" ] == 4
4280
4381 def test_get_project_inventory (self ,client ):
4482 project_id = 1
45- fake_json = """
83+ fake_response_json = """
4684{ "projectId": 1, "inventoryItems": [
4785 {"itemNumber":1, "id":1234, "name":"Example component","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"},
4886 {"itemNumber":2, "id":1235, "name":"Example component 2","type":"component","priority":"low","createdBy":"Zach","createdOn":"Today","updatedOn":"Tomorrow","componentName":"snakeyaml","componentVersionName":"2.0"}
4987 ]}
5088"""
5189 with requests_mock .Mocker () as m :
5290 m .get (f"{ TEST_URL } /codeinsight/api/project/inventory/{ project_id } " ,
53- text = fake_json )
54- projectInventory = client .project_inventory .get (project_id )
55- print (projectInventory )
91+ text = fake_response_json )
92+ projectInventory = client .projects .get_inventory (project_id )
5693 assert projectInventory .projectId == project_id
5794 assert len (projectInventory .inventoryItems ) >= 2
58-
5995
60- ## Coming soon features ##
61- def test_inventories (self , client ):
62- with pytest .raises (NotImplementedError ):
63- client .inventories () != None
96+ #### FIX THIS! ####
97+ def test_get_project_inventory_summary (self ,client ):
98+ project_id = 1
99+ fake_response_json = """ { "data": [
100+ {
101+ "itemNumber": 1,
102+ "id": 12345,
103+ "name": "Inventory Item 1",
104+ "type":"component",
105+ "priority":"low",
106+ "createdBy":"Zach",
107+ "createdOn":"Today",
108+ "updatedOn":"Tomorrow",
109+ "componentName":"snakeyaml",
110+ "componentVersionName":"2.0"
111+ },
112+ {
113+ "itemNumber": 2,
114+ "id": 12346,
115+ "name": "Inventory Item 2",
116+ "type":"component",
117+ "priority":"low",
118+ "createdBy":"Zach",
119+ "createdOn":"Today",
120+ "updatedOn":"Tomorrow",
121+ "componentName":"snakeyaml",
122+ "componentVersionName":"2.0"
123+ }
124+ ]
64125
65- def test_vulnerabilities (self , client ):
66- with pytest .raises (NotImplementedError ):
67- client .vulnerabilites () != None
126+ }
127+ """
128+ with requests_mock .Mocker () as m :
129+ m .get (f"{ TEST_URL } /codeinsight/api/projects/{ project_id } /inventorySummary" ,
130+ text = fake_response_json )
131+ project_inventory_summary = client .projects .get_inventory_summary (project_id )
132+
133+ assert len (project_inventory_summary ) == 2
134+ assert project_inventory_summary [1 ].id == 12346
135+
0 commit comments