Merge changes I4960c4a8,I8cc3c2ae
[integration/csit.git] / tests / vfc / nfvo-catalog / VNFPackageContent.robot
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 ${vnf_packages_url}         /api/vnfpkgm/v1/vnf_packages
12
13 #json files
14 ${request_json}    ${SCRIPTS}/../tests/vfc/nfvo-catalog/jsons/CreateVnfPkgInfoRequest.json
15 ${request_csar}    ${SCRIPTS}/../tests/vfc/nfvo-catalog/files/vgw.csar
16
17
18 #global variables
19 ${packageId}
20
21 *** Test Cases ***
22 Create new VNF Package Resource for pre-condition
23     Log    Create new VNF Package Resource for pre-condition
24     ${json_value}=     json_from_file      ${request_json}
25     ${json_string}=     string_from_json   ${json_value}
26     ${headers}    Create Dictionary    Content-Type=application/json    Accept=application/json
27     Create Session    web_session    http://${CATALOG_IP}:${catalog_port}    headers=${headers}
28     Set Request Body    ${json_string}
29     ${resp}=    Post Request    web_session     ${vnf_packages_url}    ${json_string}
30     Should Be Equal As Strings    201   ${resp.status_code}
31     ${response_json}    json.loads    ${resp.content}
32     Should Be Equal As Strings    CREATED    ${response_json['onboardingState']}
33     ${packageId}=    Convert To String      ${response_json['id']}
34     Set Global Variable     ${packageId}
35
36 Upload VNF Package Content
37     Log   Upload VNF Package Content
38     [Documentation]    The objective is to test the upload of a VNF Package Content in Zip format.
39     Create Session    web_session    http://${CATALOG_IP}:${catalog_port}
40     ${headers}    Create Dictionary    Accept=application/json
41     &{fileParts}=    Create Dictionary
42     Create Multi Part   ${fileParts}  file  ${request_csar}
43     Log  ${fileParts}
44     ${resp}=  Put Request  web_session  ${vnf_packages_url}/${packageId}/package_content  files=${fileParts}  headers=${headers}
45     Log  ${resp.status_code}    
46     Should Be Equal As Strings    202    ${resp.status_code}
47     Log    Received 202 Accepted as expected
48   
49 GET Individual VNF Package Content
50     Log    GET Individual VNF Package Content
51     [Documentation]    The objective is to test the retrieval of an individual VNF package content
52     ${headers}            Create Dictionary    Content-Type=application/json
53     Create Session        web_session          http://${CATALOG_IP}:${catalog_port}      headers=${headers}
54     ${resp}=              Get Request          web_session     ${vnf_packages_url}/${packageId}/package_content
55     Should Be Equal As Strings    200    ${resp.status_code}
56
57 Check Postcondition
58     Log    Check Postcondition
59     ${headers}            Create Dictionary    Content-Type=application/json    Accept=application/json
60     Create Session        web_session          http://${CATALOG_IP}:${catalog_port}      headers=${headers}
61     ${resp}=              Get Request          web_session     ${vnf_packages_url}/${packageId}
62     Should Be Equal As Strings    200    ${resp.status_code}
63     ${response_json}    json.loads    ${resp.content}
64     Should Be Equal As Strings    ONBOARDED    ${response_json['onboardingState']}
65         
66 POST Individual VNF Package Content - Method not implemented
67     Log    POST Individual VNF Package Content - Method not implemented
68     [Documentation]    The objective is to test that POST method is not allowed to create new VNF Package content
69     ${headers}            Create Dictionary    Content-Type=application/json    Accept=application/json
70     Create Session        web_session          http://${CATALOG_IP}:${catalog_port}      headers=${headers}
71     ${resp}=              Post Request          web_session     ${vnf_packages_url}/${packageId}/package_content
72     Should Be Equal As Strings    405    ${resp.status_code}
73
74 PATCH Individual VNF Package Content - Method not implemented
75     Log    PATCH Individual VNF Package Content - Method not implemented
76     [Documentation]    The objective is to test that PATCH  method is not allowed to update a VNF Package content
77     ${headers}            Create Dictionary    Content-Type=application/json    Accept=application/json
78     Create Session        web_session          http://${CATALOG_IP}:${catalog_port}      headers=${headers}
79     ${resp}=              Patch Request          web_session     ${vnf_packages_url}/${packageId}/package_content
80     Should Be Equal As Strings    405    ${resp.status_code}
81
82 DELETE Individual VNF Package Content - Method not implemented
83     Log    DELETE Individual VNF Package Content - Method not implemented
84     [Documentation]    The objective is to test that DELETE  method is not allowed to delete a VNF Package content
85     ${headers}            Create Dictionary    Content-Type=application/json    Accept=application/json
86     Create Session        web_session          http://${CATALOG_IP}:${catalog_port}      headers=${headers}
87     ${resp}=              Delete Request          web_session     ${vnf_packages_url}/${packageId}/package_content
88     Should Be Equal As Strings    405    ${resp.status_code}
89
90 *** Keywords ***
91 Create Multi Part
92     [Arguments]  ${addTo}  ${partName}  ${filePath}  ${contentType}=${None}  ${content}=${None}
93     ${fileData}=  Run Keyword If  '''${content}''' != '''${None}'''  Set Variable  ${content}
94     ...            ELSE  Get Binary File  ${filePath}
95     ${fileDir}  ${fileName}=  Split Path  ${filePath}
96     ${partData}=  Create List  ${fileName}  ${fileData}  ${contentType}
97     Set To Dictionary  ${addTo}  ${partName}=${partData}