From 65dfc9606093dd7fa8babcd6e8bceece76ca7933 Mon Sep 17 00:00:00 2001 From: Samuel Pierri Cabral Date: Fri, 29 Dec 2023 14:39:15 +0000 Subject: [PATCH] Update test cases and requirements.txt --- README.md | 2 +- SoapLibrary/SoapLibrary.py | 22 +++++----- Tests/Requests/Request_CalcPrecoPrazo.xml | 21 --------- Tests/Requests/Request_ListaServicos.xml | 6 --- Tests/Requests/busca_servicos.xml | 11 +++++ Tests/Requests/consultaCEP.xml | 10 +++++ Tests/keyword_tests.robot | 52 +++++++++++------------ requirements.txt | 10 ++--- 8 files changed, 63 insertions(+), 71 deletions(-) delete mode 100644 Tests/Requests/Request_CalcPrecoPrazo.xml delete mode 100644 Tests/Requests/Request_ListaServicos.xml create mode 100644 Tests/Requests/busca_servicos.xml create mode 100644 Tests/Requests/consultaCEP.xml diff --git a/README.md b/README.md index e39ea19..2ecb26c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SoapLibrary/SoapLibrary.py b/SoapLibrary/SoapLibrary.py index 086f8ee..f0046e0 100644 --- a/SoapLibrary/SoapLibrary.py +++ b/SoapLibrary/SoapLibrary.py @@ -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) @@ -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) @@ -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") @@ -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 @@ -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 @@ -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) diff --git a/Tests/Requests/Request_CalcPrecoPrazo.xml b/Tests/Requests/Request_CalcPrecoPrazo.xml deleted file mode 100644 index 0106fa2..0000000 --- a/Tests/Requests/Request_CalcPrecoPrazo.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - 04014 - 88132080 - 88304140 - 2 - 1 - 30 - 10 - 30 - 30 - N - 0 - S - - - \ No newline at end of file diff --git a/Tests/Requests/Request_ListaServicos.xml b/Tests/Requests/Request_ListaServicos.xml deleted file mode 100644 index 9ea11a3..0000000 --- a/Tests/Requests/Request_ListaServicos.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Tests/Requests/busca_servicos.xml b/Tests/Requests/busca_servicos.xml new file mode 100644 index 0000000..a76da68 --- /dev/null +++ b/Tests/Requests/busca_servicos.xml @@ -0,0 +1,11 @@ + + + + + 9992157880 + 0067599079 + sigep + n5f9t8 + + + \ No newline at end of file diff --git a/Tests/Requests/consultaCEP.xml b/Tests/Requests/consultaCEP.xml new file mode 100644 index 0000000..e946247 --- /dev/null +++ b/Tests/Requests/consultaCEP.xml @@ -0,0 +1,10 @@ + + + + + 88132010 + sigep + n5f9t8 + + + \ No newline at end of file diff --git a/Tests/keyword_tests.robot b/Tests/keyword_tests.robot index 4260754..59a2a5a 100644 --- a/Tests/keyword_tests.robot +++ b/Tests/keyword_tests.robot @@ -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} 53 -${request_string_500} a3 +${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} 53 +${request_string_500} a3 *** Test Cases *** Test Call Soap Method @@ -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 @@ -58,7 +58,7 @@ 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 @@ -66,7 +66,7 @@ Test Call SOAP Method with XML Anything 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 @@ -74,7 +74,7 @@ Test Call SOAP Method with String XML Anything 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} @@ -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 diff --git a/requirements.txt b/requirements.txt index e848c90..584d0ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -requests==2.31.0 -robotframework==5.0.1 -urllib3==1.26.11 -zeep==4.1.0 -lxml==4.9.1 \ No newline at end of file +requests>=2.31.0 +robotframework>=5.0.1 +urllib3>=1.26.18 +zeep>=4.2.1 +lxml>=4.9.1 \ No newline at end of file