Olivia.Zhan | 1de6ffb | 2019-07-16 10:40:16 +0800 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Resource ../../common.robot |
| 3 | Library Collections |
| 4 | Library RequestsLibrary |
| 5 | Library OperatingSystem |
| 6 | Library json |
| 7 | Library HttpLibrary.HTTP |
| 8 | |
| 9 | *** Variables *** |
| 10 | ${catalog_port} 8806 |
| 11 | ${pnf_descriptors_url} /api/nsd/v1/pnf_descriptors |
| 12 | |
| 13 | #json files |
| 14 | ${request_json} ${SCRIPTS}/../tests/vfc/nfvo-catalog/jsons/CreatePnfdInfoRequest.json |
| 15 | ${request_csar} ${SCRIPTS}/../tests/vfc/nfvo-catalog/files/ran-du.csar |
| 16 | |
| 17 | #global variables |
| 18 | ${pnfdId} |
| 19 | |
| 20 | *** Test Cases *** |
| 21 | Create new PNF Descriptor Resource for pre-condition |
| 22 | Log Create new PNF Descriptor Resource for pre-condition |
| 23 | ${json_value}= json_from_file ${request_json} |
| 24 | ${json_string}= string_from_json ${json_value} |
| 25 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 26 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 27 | Set Request Body ${json_string} |
| 28 | ${resp}= Post Request web_session ${pnf_descriptors_url} ${json_string} |
| 29 | Should Be Equal As Strings 201 ${resp.status_code} |
| 30 | ${response_json} json.loads ${resp.content} |
| 31 | Should Be Equal As Strings CREATED ${response_json['pnfdOnboardingState']} |
| 32 | ${pnfdId}= Convert To String ${response_json['id']} |
| 33 | Set Global Variable ${pnfdId} |
| 34 | |
| 35 | Upload PNFD Content |
| 36 | Log Upload PNFD Content |
| 37 | [Documentation] The objective is to test the upload of a PNFD Content |
| 38 | Create Session web_session http://${CATALOG_IP}:${catalog_port} |
| 39 | ${headers} Create Dictionary Accept=application/json |
| 40 | &{fileParts}= Create Dictionary |
| 41 | Create Multi Part ${fileParts} file ${request_csar} |
| 42 | Log ${fileParts} |
| 43 | ${resp}= Put Request web_session ${pnf_descriptors_url}/${pnfdId}/pnfd_content files=${fileParts} headers=${headers} |
| 44 | Log ${resp.status_code} |
| 45 | Should Be Equal As Strings 204 ${resp.status_code} |
| 46 | Log Received 204 Accepted as expected |
| 47 | |
| 48 | Get PNFD Content |
| 49 | Log Get PNFD Content |
| 50 | [Documentation] The objective is to test the retrieval of the PNFD Content |
| 51 | ${headers} Create Dictionary Content-Type=application/json |
| 52 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 53 | ${resp}= Get Request web_session ${pnf_descriptors_url}/${pnfdId}/pnfd_content |
| 54 | Should Be Equal As Strings 200 ${resp.status_code} |
| 55 | |
| 56 | Check Postcondition |
| 57 | Log Check Postcondition |
| 58 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 59 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 60 | ${resp}= Get Request web_session ${pnf_descriptors_url}/${pnfdId} |
| 61 | Should Be Equal As Strings 200 ${resp.status_code} |
| 62 | ${response_json} json.loads ${resp.content} |
| 63 | Should Be Equal As Strings ONBOARDED ${response_json['pnfdOnboardingState']} |
| 64 | |
| 65 | POST PNFD Content - Method not implemented |
| 66 | Log POST PNFD Content - Method not implemented |
| 67 | [Documentation] The objective is to test that POST method is not allowed to create new PNF Descriptor content |
| 68 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 69 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 70 | ${resp}= Post Request web_session ${pnf_descriptors_url}/${pnfdId}/pnfd_content |
| 71 | Should Be Equal As Strings 405 ${resp.status_code} |
| 72 | |
| 73 | PATCH PNFD Content - Method not implemented |
| 74 | Log PATCH PNFD Content - Method not implemented |
| 75 | [Documentation] The objective is to test that PATCH method is not allowed to update a PNF Descriptor content |
| 76 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 77 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 78 | ${resp}= Patch Request web_session ${pnf_descriptors_url}/${pnfdId}/pnfd_content |
| 79 | Should Be Equal As Strings 405 ${resp.status_code} |
| 80 | |
| 81 | DELETE PNFD Content - Method not implemented |
| 82 | Log DELETE PNFD Content - Method not implemented |
| 83 | [Documentation] The objective is to test that DELETE method is not allowed to delete a PNF Descriptor content |
| 84 | ${headers} Create Dictionary Content-Type=application/json Accept=application/json |
| 85 | Create Session web_session http://${CATALOG_IP}:${catalog_port} headers=${headers} |
| 86 | ${resp}= Delete Request web_session ${pnf_descriptors_url}/${pnfdId}/pnfd_content |
| 87 | Should Be Equal As Strings 405 ${resp.status_code} |
| 88 | |
| 89 | *** Keywords *** |
| 90 | Create Multi Part |
| 91 | [Arguments] ${addTo} ${partName} ${filePath} ${contentType}=${None} ${content}=${None} |
| 92 | ${fileData}= Run Keyword If '''${content}''' != '''${None}''' Set Variable ${content} |
| 93 | ... ELSE Get Binary File ${filePath} |
| 94 | ${fileDir} ${fileName}= Split Path ${filePath} |
| 95 | ${partData}= Create List ${fileName} ${fileData} ${contentType} |
| 96 | Set To Dictionary ${addTo} ${partName}=${partData} |