asyrjasalo / RESTinstance

Robot Framework library for RESTful JSON APIs
https://pypi.org/project/RESTinstance
GNU Lesser General Public License v3.0
205 stars 84 forks source link

[ WARN ] Response body content is not JSON. Content-Type is: text/plain; charset=utf-8 #85

Closed ecarmiel closed 3 years ago

ecarmiel commented 4 years ago

Hi i wrote a test for http response 404 , the robot test is passing but there is a Warning. the response i'm getting isn't json but text/plain this is from the server.

My test:

*** Settings ***
Suite Setup   Prepare Enviorment
Resource   ../Resource/Keywords.robot
Resource   ../Resource/resource.robot
Library     OperatingSystem
Library     REST      ${url}

*** Test Cases ***
Endc-setup - Http response 404
    POST        /v1/nodeb/
    Output
    Integer    response status   404

Result 
==============================================================================
Setup Request HttpResponse404                                                 
==============================================================================
[ WARN ] Response body content is not JSON. Content-Type is: text/plain; charset=utf-8**
Endc-setup - Http response 404                                        .
{
    "request": {
        "method": "POST",
        "url": "http://localhost:3800/v1/nodeb/",
        "scheme": "http",
        "netloc": "localhost:3800",
        "path": "/v1/nodeb/",
        "query": {},
        "body": null,
        "headers": {
            "Accept": "application/json, */*",
            "Content-Type": "application/json",
            "User-Agent": "RESTinstance/1.0.0"
        },
        "proxies": {},
        "timeout": [
            null,
            null
        ],
        "cert": null,
        "sslVerify": true,
        "allowRedirects": true,
        "timestamp": {
            "utc": "2019-09-18T13:35:28.367865+00:00",
            "local": "2019-09-18T16:35:28.367865+03:00"
        }
    },
    "response": {
        "seconds": 0.0017439999999999999,
        "status": 404,
        "body": "404 page not found\n",
        "headers": {
            "Content-Type": "text/plain; charset=utf-8",
            "X-Content-Type-Options": "nosniff",
            "Date": "Wed, 18 Sep 2019 13:35:28 GMT",
            "Content-Length": "19"
        }
    }
}
Endc-setup - Http response 404                                        | PASS |
------------------------------------------------------------------------------
Setup Request HttpResponse404                                         | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
DoanhPoPu commented 4 years ago

The warning message come from following block of codes. try: response_body = response.json() except ValueError: response_body = response.text if response_body: logger.warn( "Response body content is not JSON. "

Thanks, DoanhPoPu

ecarmiel commented 4 years ago

The warning message come from following block of codes. try: response_body = response.json() except ValueError: response_body = response.text if response_body: logger.warn( "Response body content is not JSON. "

  • "Content-Type is: %s" % response.headers["Content-Type"] ) If we're going to support more data format, so the Json validation should be executed if response data is Json. If not, we need to skip validations.

Thanks, DoanhPoPu

Is there a way i can remove this WARN from my tests ?

DoanhPoPu commented 4 years ago

We need to ask owner @asyrjasalo to change the log level to info (Change logger.warn --> logger.info) It will NOT show into the robot results

asimell commented 3 years ago

We'll probably add a keyword or other customization option to change the log level for the warning.

asimell commented 3 years ago

This has been implemented and merged to Eficode fork of this repository. We'll create a release PR to this repo once we get the release content ready.