Skip to content

Commit

Permalink
Merge pull request #52 from Altran-PT-GDC/update_tests
Browse files Browse the repository at this point in the history
Update test cases and requirements.txt
  • Loading branch information
samuelpcabral authored Dec 29, 2023
2 parents a452410 + 65dfc96 commit b4ce631
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 71 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![PyPi downloads](https://img.shields.io/pypi/dm/robotframework-soaplibrary.svg)](https://pypi.org/project/robotframework-soaplibrary)
[![Total downloads](https://static.pepy.tech/personalized-badge/robotframework-soaplibrary?period=total&units=international_system&left_color=lightgrey&right_color=yellow&left_text=Total)](https://pypi.org/project/robotframework-soaplibrary)
[![Latest Version](https://img.shields.io/pypi/v/robotframework-soaplibrary.svg)](https://pypi.org/project/robotframework-soaplibrary)
[![Tests](https://github.com/Altran-PT-GDC/Robot-Framework-SOAP-Library/actions/workflows/python-app.yml/badge.svg?branch=master)](https://github.com/Altran-PT-GDC/Robot-Framework-SOAP-Library/actions/workflows/python-app.yml)
[![tests](https://github.com/Altran-PT-GDC/Robot-Framework-SOAP-Library/actions/workflows/python-app.yml/badge.svg?branch=master)](https://github.com/Altran-PT-GDC/Robot-Framework-SOAP-Library/actions/workflows/python-app.yml)


# Robot-Framework-SOAP-Library
Expand Down
22 changes: 11 additions & 11 deletions SoapLibrary/SoapLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ def call_soap_method_xml(self, xml, headers=DEFAULT_HEADERS, status=None):
| status | optional string: anything |
*Example:*
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request_status_500.xml | status=anything |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request_status_500.xml | status=anything |
"""
raw_text_xml = self._convert_xml_to_raw_text(xml)
xml_obj = etree.fromstring(raw_text_xml)
Expand All @@ -114,9 +114,9 @@ def get_data_from_xml_tag(self, xml, tag, index=1):
| index | tag index if there are multiple tags with the same name, starting at 1. Default is set to 1 |
*Examples:*
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${value}= | Get Data From XML By Tag | ${response} | SomeTag |
| ${value}= | Get Data From XML By Tag | ${response} | SomeTag | index=9 |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${value}= | Get Data From XML By Tag | ${response} | SomeTag |
| ${value}= | Get Data From XML By Tag | ${response} | SomeTag | index=9 |
"""
new_index = index - 1
xpath = self._parse_xpath(tag)
Expand All @@ -126,8 +126,8 @@ def get_data_from_xml_tag(self, xml, tag, index=1):
if len(data_list) == 0:
logger.warn('The search "%s" did not return any result! Please confirm the tag!' % xpath)
elif len(data_list) > 1:
logger.warn('The tag you entered found %s items, returning the text in the index '
'number %s, if you want a different index inform the argument index=N' % (len(data_list), index))
logger.debug('The tag you entered found %s items, returning the text in the index '
'number %s, if you want a different index inform the argument index=N' % (len(data_list), index))
return data_list[new_index].text

@keyword("Edit XML Request")
Expand Down Expand Up @@ -188,8 +188,8 @@ def save_xml_to_file(self, etree_xml, save_folder, file_name):
| file_name | name of the new xml file without .xml |
*Example*:
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response_file}= | Save XML To File | ${response} | ${CURDIR} | response_file_name |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response_file}= | Save XML To File | ${response} | ${CURDIR} | response_file_name |
"""
new_file_path = self._save_to_file(save_folder, file_name, etree.tostring(etree_xml, pretty_print=True))
return new_file_path
Expand All @@ -204,7 +204,7 @@ def convert_response_dict(self, xml_etree):
| xml_etree | etree object of the xml to convert to dictionary |
*Example:*
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${dict_response}= | Convert XML Response to Dictionary | ${response} |
"""
# Thanks to Jamie Murphy for this code: https://gist.github.com/jacobian/795571
Expand Down Expand Up @@ -275,7 +275,7 @@ def decode_base64(self, response):
| response | Response of the webservice coded in base64 |
*Example:*
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response}= | Call SOAP Method With XML | ${CURDIR}${/}Request.xml |
| ${response_decoded}= | Decode Base64 | ${response} |
"""
response_decode = base64.b64decode(response)
Expand Down
21 changes: 0 additions & 21 deletions Tests/Requests/Request_CalcPrecoPrazo.xml

This file was deleted.

6 changes: 0 additions & 6 deletions Tests/Requests/Request_ListaServicos.xml

This file was deleted.

11 changes: 11 additions & 0 deletions Tests/Requests/busca_servicos.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header/>
<soapenv:Body>
<cli:buscaServicos>
<idContrato>9992157880</idContrato>
<idCartaoPostagem>0067599079</idCartaoPostagem>
<usuario>sigep</usuario>
<senha>n5f9t8</senha>
</cli:buscaServicos>
</soapenv:Body>
</soapenv:Envelope>
10 changes: 10 additions & 0 deletions Tests/Requests/consultaCEP.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header/>
<soapenv:Body>
<cli:consultaCEP>
<cep>88132010</cep>
<usuario>sigep</usuario>
<senha>n5f9t8</senha>
</cli:consultaCEP>
</soapenv:Body>
</soapenv:Envelope>
52 changes: 25 additions & 27 deletions Tests/keyword_tests.robot
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Library XML use_lxml=True
Library Process

*** Variables ***
${requests_dir} ${CURDIR}${/}Requests
${wsdl_correios_price_calculator} http://ws.correios.com.br/calculador/CalcPrecoPrazo.asmx?wsdl
${wsdl_country_info} http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?wsdl
${wsdl_calculator} https://ecs.syr.edu/faculty/fawcett/Handouts/cse775/code/calcWebService/Calc.asmx?wsdl
${request_string} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><Add xmlns="http://tempuri.org/"><a>5</a><b>3</b></Add></Body></Envelope>
${request_string_500} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><Add xmlns="http://tempuri.org/"><a>a</a><b>3</b></Add></Body></Envelope>
${requests_dir} ${CURDIR}${/}Requests
${wsdl_correios} https://apphom.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente?wsdl
${wsdl_country_info} http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?wsdl
${wsdl_calculator} https://ecs.syr.edu/faculty/fawcett/Handouts/cse775/code/calcWebService/Calc.asmx?wsdl
${request_string} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><Add xmlns="http://tempuri.org/"><a>5</a><b>3</b></Add></Body></Envelope>
${request_string_500} <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Body><Add xmlns="http://tempuri.org/"><a>a</a><b>3</b></Add></Body></Envelope>

*** Test Cases ***
Test Call Soap Method
Expand All @@ -26,28 +26,28 @@ Test Call Soap Method Error
${response} Call SOAP Method Add 2 X status=anything
Should Contain ${response} Input string was not in a correct format.

Test read
Test Read
[Tags] calculator
Create Soap Client ${wsdl_calculator} ssl_verify=False
${response} Call SOAP Method With XML ${requests_dir}${/}Request_Calculator.xml
${result} Get Data From XML By Tag ${response} AddResult
should be equal 8 ${result}

Test read With Binding Address
Test Read With Binding Address
[Tags] calculator
Create Soap Client ${wsdl_calculator} ssl_verify=False use_binding_address=True
${response} Call SOAP Method With XML ${requests_dir}${/}Request_Calculator.xml
${result} Get Data From XML By Tag ${response} AddResult
should be equal 8 ${result}

Test read string xml
Test Read String Xml
[Tags] calculator
Create Soap Client ${wsdl_calculator} ssl_verify=False
${response} Call SOAP Method With String XML ${request_string}
${result} Get Data From XML By Tag ${response} AddResult
should be equal 8 ${result}

Test Edit and Read
Test Edit And Read
[Tags] calculator
Remove File ${requests_dir}${/}New_Request_Calculator.xml
Create Soap Client ${wsdl_calculator} ssl_verify=False
Expand All @@ -58,23 +58,23 @@ Test Edit and Read
should be equal 14 ${result}
Should Exist ${requests_dir}${/}New_Request_Calculator.xml

Test Call SOAP Method with XML Anything
Test Call Soap Method With XML Anything
[Tags] calculator
Create Soap Client ${wsdl_calculator} ssl_verify=False
${response} Call SOAP Method With XML ${requests_dir}${/}Request_Calculator_500.xml status=anything
${result} Get Data From XML By Tag ${response} faultstring
log ${result}
Should Contain ${result} Server was unable to read request.

Test Call SOAP Method with String XML Anything
Test Call SOAP Method With String XML Anything
[Tags] calculator
Create Soap Client ${wsdl_calculator} ssl_verify=False
${response} Call SOAP Method With String XML ${request_string_500} status=anything
${result} Get Data From XML By Tag ${response} faultstring
log ${result}
Should Contain ${result} Server was unable to read request.

Test read utf8
Test Read UTF8
[Tags] country_info
#todo find an API with response in utf8
Create Soap Client ${wsdl_country_info}
Expand All @@ -99,27 +99,25 @@ Test Save File Response
${file} Save XML To File ${response} ${CURDIR} response_test
Should Exist ${CURDIR}${/}response_test.xml

Test Read tags with index
Test Read Tags With Index
[Tags] correios
Create Soap Client ${wsdl_correios_price_calculator}
${response} Call SOAP Method With XML ${requests_dir}${/}Request_ListaServicos.xml
${codigo} Get Data From XML By Tag ${response} codigo index=99
should be equal as integers 11835 ${codigo}
Create Soap Client ${wsdl_correios}
${response} Call SOAP Method With XML ${requests_dir}${/}busca_servicos.xml
${codigo} Get Data From XML By Tag ${response} codigo index=33
Should Be Equal As Integers ${codigo} 03336

Test Response to Dict
Test Response To Dict
[Tags] correios
Create Soap Client ${wsdl_correios_price_calculator}
${response} Call SOAP Method With XML ${requests_dir}${/}Request_CalcPrecoPrazo.xml
Create Soap Client ${wsdl_correios}
${response} Call SOAP Method With XML ${requests_dir}${/}consultaCEP.xml
${dict_response} Convert XML Response to Dictionary ${response}
${type} evaluate str(type(${dict_response}))
Should Contain ${type} 'dict'
${body} Get From Dictionary ${dict_response} Body
${calcprecoprazoresponse} Get From Dictionary ${body} CalcPrecoPrazoResponse
${calcprecoprazoresult} Get From Dictionary ${calcprecoprazoresponse} CalcPrecoPrazoResult
${servicos} Get From Dictionary ${calcprecoprazoresult} Servicos
${cservico} Get From Dictionary ${servicos} cServico
${valorsemadicionais} Get From Dictionary ${cservico} ValorSemAdicionais
should be equal 24,90 ${valorsemadicionais}
${city} Set Variable ${dict_response}[Body][consultaCEPResponse][return][cidade]
${uf} Set Variable ${dict_response}[Body][consultaCEPResponse][return][uf]
Should Be Equal ${city} Palhoça
Should Be Equal ${uf} SC

Test Edit XML Request 1
[Tags] edit_xml
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
requests==2.31.0
robotframework==5.0.1
urllib3==1.26.11
zeep==4.1.0
lxml==4.9.1
requests>=2.31.0
robotframework>=5.0.1
urllib3>=1.26.18
zeep>=4.2.1
lxml>=4.9.1

1 comment on commit b4ce631

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass %
21 0 0 21 100

Passed Tests

Name ⏱️ Duration Suite
Test Call Soap Method 0.281 s Keyword Tests
Test Call Soap Method Error 0.098 s Keyword Tests
Test Read 0.101 s Keyword Tests
Test Read With Binding Address 0.097 s Keyword Tests
Test Read String Xml 0.189 s Keyword Tests
Test Edit And Read 0.1 s Keyword Tests
Test Call Soap Method With XML Anything 0.099 s Keyword Tests
Test Call SOAP Method With String XML Anything 0.098 s Keyword Tests
Test Read UTF8 0.611 s Keyword Tests
Test Get Last Response Object 0.439 s Keyword Tests
Test Save File Response 0.485 s Keyword Tests
Test Read Tags With Index 5.085 s Keyword Tests
Test Response To Dict 1.464 s Keyword Tests
Test Edit XML Request 1 0.01 s Keyword Tests
Test Edit XML Request 2 0.008 s Keyword Tests
Test Edit XML Request 3 0.008 s Keyword Tests
Test Edit XML Request 4 0.008 s Keyword Tests
Test Edit XML Request 5 0.01 s Keyword Tests
Test Edit XML Request 6 0.009 s Keyword Tests
Test Edit XML Request 7 0.008 s Keyword Tests
Test Edit XML Request 8 0.007 s Keyword Tests

Please sign in to comment.