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

Fail on using "POST" more than once #70

Closed vitlumin closed 3 years ago

vitlumin commented 5 years ago

I have test cases like below. exactly the same, but failed on the second. How could it be?

*** Test Cases ***
Login Success
    POST    ${api root path}/${apiCategory}/${apiVersion}/oauth/token    {"grantType": "${grantType}", "userName": "${userName}", "value": "${value}"}
    Expect response    {"status": 200}

Login Success_1
    POST    ${api root path}/${apiCategory}/${apiVersion}/oauth/token    {"grantType": "${grantType}", "userName": "${userName}", "value": "${value}"}
    Expect response    {"status": 200}
robot --loglevel Debug NBM_5G/OperationService/SecurityManagement/test.robot 
==============================================================================
Test                                                                          
==============================================================================
Login Success                                                         | PASS |
------------------------------------------------------------------------------
Login Success_1                                                       | FAIL |
AttributeError: 'int' object has no attribute 'get'
------------------------------------------------------------------------------
Test                                                                  | FAIL |
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
==============================================================================
Output:  /home/auto/output.xml
Log:     /home/auto/log.html
Report:  /home/auto/report.html
asimell commented 3 years ago

Is this still an issue?

I believe your API prevents 2 identical calls. In your first test you POST (create a new user(?)) and then in the next you try to create that exact same new user again, which then fails as the user already exists. This seems more like a test design issue rather than library issue.

If the error happens always on the second executed test when you run robot with --randomize flag, then I believe that is the cause. In order to update existing data you should use PUT or PATCH requests instead of POST.