You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all thank you for publishing this API. It was a great fun to play with it. It helped me learn a few things about REST API.
Now, to the point. I came a cross with some problem while writing tests for the API. See description below.
Short problem description.
I am talking about POST '/register/car' method, lines 192-208. It appears that POST '/register/car' method fails in case car not in the list. As a result clients gets error 500.
Step by step:
Send POST '/register/car' request using car data that not in the cars_list
Verify HTTP response
Actual result: error 500 INTERNAL SERVER ERROR
Expected result: error 401 with some proper error text
Comments:
POST '/register/car' method works fine when using a proper car data.
2. HTTP response (header only):
HTTP/1.0 500 INTERNAL SERVER ERROR
Logs from CMD:
Serving Flask app "cars_app" (lazy loading)
Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
Debug mode: on
Restarting with stat
Debugger is active!
Debugger PIN: 105-519-712
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
POST debug: ImmutableMultiDict([('car_name', 'figo'), ('brand', 'Ford')])
127.0.0.1 - - [04/Oct/2019 16:30:33] "POST /register/car?car_name=figo&brand=Ford HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2463, in call
return self.wsgi_app(environ, start_response)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\api\cars_app.py", line 118, in decorated
return f(*args, **kwargs)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\api\cars_app.py", line 258, in register_car
registered_car = {'car': car[0], 'customer_details': request.json,
IndexError: list index out of range
Thanks
The text was updated successfully, but these errors were encountered:
Hi all.
First of all thank you for publishing this API. It was a great fun to play with it. It helped me learn a few things about REST API.
Now, to the point. I came a cross with some problem while writing tests for the API. See description below.
Short problem description.
I am talking about POST '/register/car' method, lines 192-208. It appears that POST '/register/car' method fails in case car not in the list. As a result clients gets error 500.
Step by step:
Actual result: error 500 INTERNAL SERVER ERROR
Expected result: error 401 with some proper error text
Comments:
POST '/register/car' method works fine when using a proper car data.
Test code snippet (Python3 + pytest):
self.URL = 'http://127.0.0.1:5000'
self.register_url = '/register/car'
self.customer = {'customer_name': 'Unai Emery', 'city': 'London'}
self.new_car = {'car_name': 'figo', 'brand': 'Ford'}
username = USER_LIST[0]['name']
password = USER_LIST[0]['password']
response = requests.post(url=self.URL +
self.register_url,
params=self.new_car,
json=self.customer,
auth=(username, password))
self.assertEqual(200, response.status_code)
Logs from Fiddler Web Debbuger:
1. HTTP request:
POST http://127.0.0.1:5000/register/car?car_name=figo&brand=Ford HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: python-requests/2.22.0
Accept-Encoding: gzip, deflate
Accept: /
Connection: keep-alive
Content-Length: 49
Content-Type: application/json
Authorization: Basic cXhmMjpxeGYy
{"customer_name": "Unai Emery", "city": "London"}
2. HTTP response (header only):
HTTP/1.0 500 INTERNAL SERVER ERROR
Logs from CMD:
Serving Flask app "cars_app" (lazy loading)
Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
Debug mode: on
Restarting with stat
Debugger is active!
Debugger PIN: 105-519-712
Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
POST debug: ImmutableMultiDict([('car_name', 'figo'), ('brand', 'Ford')])
Cars list: [
{'name': 'Swift', 'brand': 'Maruti', 'price_range': '3-5 lacs', 'car_type': 'hatchback'},
{'name': 'Creta', 'brand': 'Hyundai', 'price_range': '8-14 lacs', 'car_type': 'hatchback'},
{'name': 'City', 'brand': 'Honda', 'price_range': '3-6 lacs', 'car_type': 'sedan'},
{'name': 'Vento', 'brand': 'Volkswagen', 'price_range': '7-10 lacs', 'car_type': 'sedan'}
]
127.0.0.1 - - [04/Oct/2019 16:30:33] "POST /register/car?car_name=figo&brand=Ford HTTP/1.1" 500 -
Traceback (most recent call last):
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2463, in call
return self.wsgi_app(environ, start_response)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask_compat.py", line 39, in reraise
raise value
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\venv\lib\site-packages\flask\app.py", line 1935, in dispatch_request
return self.view_functionsrule.endpoint
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\api\cars_app.py", line 118, in decorated
return f(*args, **kwargs)
File "C:\Users\superadmin\Documents\GitHub\REST_API_AUTOMATION\api\cars_app.py", line 258, in register_car
registered_car = {'car': car[0], 'customer_details': request.json,
IndexError: list index out of range
Thanks
The text was updated successfully, but these errors were encountered: