MarketSquare / robotframework-requests

Robot Framework keyword library wrapper for requests
http://marketsquare.github.io/robotframework-requests/
MIT License
487 stars 280 forks source link

"Status Should Be" uses last request even if a response is provided #383

Closed apallier closed 11 months ago

apallier commented 12 months ago

Version: 0.9.2 (but should exit in every versions until now)

Steps to reproduce

Here a minimal code reproducing the problem:

*** Settings ***
Library    RequestsLibrary

*** Test Cases ***
Test
    ${response_error}=     GET    https://www.google.com/404    expected_status=any
    ${response_ok}=     GET    https://www.google.com    expected_status=any
    Status Should Be    404    ${response_error}

Actual result

Keyword Status Should Be fails:

==============================================================================
Bug Requests Library                                                          
==============================================================================
Test                                                                  | FAIL |
Url: https://www.google.com/ Expected status: 200 != 404
------------------------------------------------------------------------------
Bug Requests Library                                                  | FAIL |
1 test, 0 passed, 1 failed
==============================================================================

Actual result

Keyword Status Should Be should pass because response ${response_error} is actually a 404 error

Investigation

  1. It seems that a Requests Response in error is considered as "False". See this code

  2. And so the following code takes the "last response" if the Response is in error (the response provided in parameter is ignored): See this code :

@keyword("Status Should Be")
def status_should_be(self, expected_status, response=None, msg=None):
    if not response:
        response = self.last_response
    self._check_status(expected_status, response, msg)
lucagiove commented 12 months ago

Ouch, thanks for the detailed report I'll have a look

apallier commented 11 months ago

Thanks for the fix 👍