Skip to content

Commit

Permalink
Revert "[REFACTOR]"
Browse files Browse the repository at this point in the history
This reverts commit 037b9a0.

The original refactor was spurred my a misunderstanding of mine (not
realizing that the value returned by the execute() function was not a
dictionary).
  • Loading branch information
james-bostock-cx committed Oct 18, 2024
1 parent 917cf15 commit 184d5fc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 59 deletions.
101 changes: 51 additions & 50 deletions CheckmarxPythonSDK/CxPortalSoapApiSDK/CxPortalWebService.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ def add_license_expiration_notification():
"""
Returns:
CxWSBasicRepsonse
{
'IsSuccesfull': True,
'ErrorMessage': None
}
"""

@retry_when_unauthorized
Expand All @@ -29,7 +25,10 @@ def execute():

response = execute()

return response
return {
"IsSuccesfull": response["IsSuccesfull"],
"ErrorMessage": response["ErrorMessage"]
}


def create_new_preset(query_ids, name):
Expand All @@ -40,26 +39,21 @@ def create_new_preset(query_ids, name):
name (str):
Returns:
CxWSResponsePresetDetails
dict
sample return:
{
'IsSuccesfull': True,
'ErrorMessage': None,
'preset': {
'queryIds': {
'long': [
343
]
},
'id': 100006,
'name': 'ddd10',
'owningteam': 1,
'isPublic': True,
'owner': None,
'isUserAllowToUpdate': True,
'isUserAllowToDelete': True,
'IsDuplicate': False
}
'queryIds': [
343
],
'id': 110003,
'name': 'ddd',
'owningteam': 1,
'isPublic': True,
'owner': None,
'isUserAllowToUpdate': True,
'isUserAllowToDelete': True,
'IsDuplicate': False
}
"""

Expand All @@ -76,7 +70,22 @@ def execute():
return client.service.CreateNewPreset(sessionId="0", presrt=cx_preset_detail)

response = execute()
return response
preset = response.preset
return {
"IsSuccesfull": response["IsSuccesfull"],
"ErrorMessage": response["ErrorMessage"],
"preset": {
'queryIds': preset["queryIds"]["long"],
'id': preset["id"],
'name': preset["name"],
'owningteam': preset["owningteam"],
'isPublic': preset["isPublic"],
'owner': preset["owner"],
'isUserAllowToUpdate': preset["isUserAllowToUpdate"],
'isUserAllowToDelete': preset["isUserAllowToDelete"],
'IsDuplicate': preset["IsDuplicate"]
} if preset else None
}


def create_scan_report(scan_id, report_type, queries_all=True, queries_ids=None, results_severity_all=True,
Expand Down Expand Up @@ -141,12 +150,7 @@ def create_scan_report(scan_id, report_type, queries_all=True, queries_ids=None,
results_display_option_snippets_mode (str): "None", "SourceAndDestination", "Full"
Returns:
CxWSCreateReportResponse
{
'IsSuccesfull': True,
'ErrorMessage': None,
'ID': 336
}
"""

@retry_when_unauthorized
Expand Down Expand Up @@ -243,7 +247,12 @@ def execute():
return client.service.CreateScanReport(SessionID="0", Report=filtered_report_request)

response = execute()
return response

return {
"IsSuccesfull": response["IsSuccesfull"],
"ErrorMessage": response["ErrorMessage"],
"ID": response["ID"]
}


def delete_preset(preset_id):
Expand All @@ -253,11 +262,7 @@ def delete_preset(preset_id):
preset_id (int):
Returns:
CxWSBasicRepsonse
{
'IsSuccesfull': True,
'ErrorMessage': None
}
"""

@retry_when_unauthorized
Expand All @@ -266,7 +271,10 @@ def execute():
return client.service.DeletePreset(sessionId="0", id=preset_id)

response = execute()
return response
return {
"IsSuccesfull": response["IsSuccesfull"],
"ErrorMessage": response["ErrorMessage"]
}


def delete_project(project_id):
Expand All @@ -276,17 +284,7 @@ def delete_project(project_id):
project_id (int):
Returns:
CxWSResponseDeleteProjects
{
'IsSuccesfull': True,
'ErrorMessage': None,
'IsConfirmation': False,
'Flags': [
'None'
],
'UndeletedProjects': None,
'NumOfDeletedProjects': 1
}
"""

@retry_when_unauthorized
Expand All @@ -295,7 +293,10 @@ def execute():
return client.service.DeleteProject(sessionID="0", projectID=project_id)

response = execute()
return response
return {
"IsSuccesfull": response["IsSuccesfull"],
"ErrorMessage": response["ErrorMessage"]
}


def delete_projects(project_ids, flag="None"):
Expand Down
18 changes: 9 additions & 9 deletions tests/CxSAST/CxPortalSOAP/test_cx_portal_web_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@

def test_add_license_expiration_notification():
response = add_license_expiration_notification()
assert response.IsSuccesfull is True
assert response.get("IsSuccesfull") is True


def test_create_new_preset():
response = create_new_preset(query_ids=[343], name="ddd10")
assert response.IsSuccesfull is True
assert response['IsSuccesfull'] is True


def test_create_scan_report():
Expand All @@ -54,23 +54,23 @@ def test_create_scan_report():
display_categories_all=False,
display_categories_ids=list(range(30, 62))
)
assert response.IsSuccesfull is True
assert response.ID > 0
assert response["IsSuccesfull"] is True
assert response["ID"] > 0


def test_delete_preset():
response = delete_preset(preset_id=100006)
assert response.IsSuccesfull is True
response = delete_preset(preset_id=120006)
assert response["IsSuccesfull"] is True


def test_delete_project():
response = delete_project(project_id=94)
assert response.IsSuccesfull is True
response = delete_project(project_id=3)
assert response["IsSuccesfull"] is True


def test_delete_projects():
response = delete_projects(project_ids=[8], flag="OnlyAllowedProjects")
assert response.IsSuccesfull is True
assert response["IsSuccesfull"] is True


def test_export_preset():
Expand Down

0 comments on commit 184d5fc

Please sign in to comment.