-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(project CreateBom): write control file with attachment details
This can be used to check meta data of attachments before feeding the list into "bom downloadAttachments".
- Loading branch information
Showing
4 changed files
with
190 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,7 @@ def test_project_not_found(self) -> None: | |
args.verbose = True | ||
args.id = "34ef5c5452014c52aa9ce4bc180624d8" | ||
args.outputfile = self.OUTPUTFILE | ||
args.controlfile = None | ||
|
||
self.add_login_response() | ||
|
||
|
@@ -126,19 +127,12 @@ def test_project_not_found(self) -> None: | |
except SystemExit as ex: | ||
self.assertEqual(ResultCode.RESULT_ERROR_ACCESSING_SW360, ex.code) | ||
|
||
@responses.activate | ||
def test_project_by_id(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBase.MYTOKEN, url=TestBase.MYURL) | ||
|
||
def add_project_releases_responses(self): | ||
# the project | ||
project = self.get_project_for_test() | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/projects/p001", | ||
json=project, | ||
json=self.get_project_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
|
@@ -165,7 +159,7 @@ def test_project_by_id(self): | |
"attachmentType": "SOURCE_SELF", | ||
"_links": { | ||
"self": { | ||
"href": "https://my.server.com/resource/api/attachments/r002a002" | ||
"href": "https://my.server.com/resource/api/attachments/r002a003" | ||
} | ||
} | ||
}) | ||
|
@@ -175,7 +169,7 @@ def test_project_by_id(self): | |
"attachmentType": "CLEARING_REPORT", | ||
"_links": { | ||
"self": { | ||
"href": "https://my.server.com/resource/api/attachments/r002a003" | ||
"href": "https://my.server.com/resource/api/attachments/r002a004" | ||
} | ||
} | ||
}) | ||
|
@@ -188,8 +182,19 @@ def test_project_by_id(self): | |
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
return release | ||
|
||
cdx_bom = sut.create_project_cdx_bom("p001") | ||
@responses.activate | ||
def test_project_by_id(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBase.MYTOKEN, url=TestBase.MYURL) | ||
|
||
release = self.add_project_releases_responses() | ||
project = self.get_project_for_test() | ||
|
||
cdx_bom, _ = sut.create_project_cdx_bom("p001", create_controlfile=False) | ||
cx_comp = cdx_bom.components[0] | ||
self.assertEqual(cx_comp.purl, release["externalIds"]["package-url"]) | ||
|
||
|
@@ -210,15 +215,15 @@ def test_project_by_id(self): | |
self.assertEqual(len(ext_refs), 1) | ||
self.assertEqual(ext_refs[0].url, release["_embedded"]["sw360:attachments"][1]["filename"]) | ||
self.assertEqual(ext_refs[0].type, ExternalReferenceType.OTHER) | ||
self.assertEqual(ext_refs[0].comment, CaPyCliBom.CLI_FILE_COMMENT + ", sw360Id: r002a002") | ||
self.assertEqual(ext_refs[0].comment, CaPyCliBom.CLI_FILE_COMMENT) | ||
self.assertEqual(ext_refs[0].hashes[0].alg, "SHA-1") | ||
self.assertEqual(ext_refs[0].hashes[0].content, release["_embedded"]["sw360:attachments"][1]["sha1"]) | ||
|
||
ext_refs = [e for e in cx_comp.external_references | ||
if e.comment and e.comment.startswith(CaPyCliBom.CRT_FILE_COMMENT)] | ||
self.assertEqual(len(ext_refs), 1) | ||
self.assertEqual(ext_refs[0].url, release["_embedded"]["sw360:attachments"][3]["filename"]) | ||
self.assertEqual(ext_refs[0].comment, CaPyCliBom.CRT_FILE_COMMENT + ", sw360Id: r002a003") | ||
self.assertEqual(ext_refs[0].comment, CaPyCliBom.CRT_FILE_COMMENT) | ||
self.assertEqual(ext_refs[0].type, ExternalReferenceType.OTHER) | ||
self.assertEqual(ext_refs[0].hashes[0].alg, "SHA-1") | ||
self.assertEqual(ext_refs[0].hashes[0].content, release["_embedded"]["sw360:attachments"][3]["sha1"]) | ||
|
@@ -231,6 +236,71 @@ def test_project_by_id(self): | |
self.assertEqual(cdx_bom.metadata.component.version, project["version"]) | ||
self.assertEqual(cdx_bom.metadata.component.description, project["description"]) | ||
|
||
@responses.activate | ||
def test_project_by_id_controlfile(self): | ||
sut = CreateBom() | ||
self.add_login_response() | ||
sut.login(token=TestBase.MYTOKEN, url=TestBase.MYURL) | ||
|
||
self.add_project_releases() | ||
|
||
# attachment info | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r001a001", | ||
body=""" | ||
{ | ||
"filename": "CLIXML_wheel-0.38.4.xml", | ||
"sha1": "ccd9f1ed2f59c46ff3f0139c05bfd76f83fd9851", | ||
"attachmentType": "COMPONENT_LICENSE_INFO_XML" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a002", | ||
body=""" | ||
{ | ||
"filename": "CLIXML_clipython-1.3.0.xml", | ||
"sha1": "dd4c38387c6811dba67d837af7742d84e61e20de", | ||
"attachmentType": "COMPONENT_LICENSE_INFO_XML", | ||
"checkedBy": "[email protected]", | ||
"checkStatus": "ACCEPTED", | ||
"createdBy": "[email protected]" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a004", | ||
body=""" | ||
{ | ||
"filename": "clipython-1.3.0.docx", | ||
"sha1": "f0d8f2ddd017bdeaecbaec72ff76a6c0a045ec66", | ||
"attachmentType": "CLEARING_REPORT" | ||
}""", | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
|
||
_, controlfile = sut.create_project_cdx_bom("p001", create_controlfile=True) | ||
self.assertEqual(controlfile['ProjectName'], 'CaPyCLI, 1.9.0') | ||
self.assertEqual(controlfile['Components'][0]['ComponentName'], 'cli-support 1.3') | ||
self.assertEqual(controlfile['Components'][0]['Sw360Id'], 'r002') | ||
self.assertEqual(controlfile['Components'][0]['Sw360AttachmentId'], 'r002a002') | ||
self.assertEqual(controlfile['Components'][0]['CliFile'], 'CLIXML_clipython-1.3.0.xml') | ||
self.assertEqual(controlfile['Components'][0]['CheckedBy'], '[email protected]') | ||
self.assertEqual(controlfile['Components'][0]['CheckStatus'], 'ACCEPTED') | ||
self.assertEqual(controlfile['Components'][0]['CreatedBy'], '[email protected]') | ||
|
||
self.assertEqual(controlfile['Components'][1]['ReportFile'], 'clipython-1.3.0.docx') | ||
|
||
@responses.activate | ||
def test_project_show_by_name(self): | ||
sut = CreateBom() | ||
|
@@ -246,6 +316,7 @@ def test_project_show_by_name(self): | |
args.name = "CaPyCLI" | ||
args.version = "1.9.0" | ||
args.outputfile = self.OUTPUTFILE | ||
args.controlfile = None | ||
|
||
self.add_login_response() | ||
|
||
|
@@ -329,6 +400,65 @@ def test_project_show_by_name(self): | |
|
||
self.delete_file(self.OUTPUTFILE) | ||
|
||
@responses.activate | ||
def test_create_project_bom_release_error(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBase.MYTOKEN, url=TestBase.MYURL) | ||
|
||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r001", | ||
status=404, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r002", | ||
json=self.get_release_cli_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
with self.assertRaises(SystemExit): | ||
bom, _ = sut.create_project_bom(self.get_project_for_test(), create_controlfile=False) | ||
|
||
@responses.activate | ||
def test_create_project_bom_controlfile_attachment_error(self): | ||
sut = CreateBom() | ||
|
||
self.add_login_response() | ||
sut.login(token=TestBase.MYTOKEN, url=TestBase.MYURL) | ||
|
||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r001", | ||
json=self.get_release_wheel_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
responses.GET, | ||
url=self.MYURL + "resource/api/releases/r002", | ||
json=self.get_release_cli_for_test(), | ||
status=200, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
responses.add( | ||
method=responses.GET, | ||
url=self.MYURL + "resource/api/attachments/r002a002", | ||
status=404, | ||
content_type="application/json", | ||
adding_headers={"Authorization": "Token " + self.MYTOKEN}, | ||
) | ||
|
||
with self.assertRaises(SystemExit): | ||
bom, _ = sut.create_project_bom(self.get_project_for_test(), create_controlfile=True) | ||
|
||
|
||
if __name__ == "__main__": | ||
APP = TestCreateBom() | ||
|